X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=advent14%2FMain.hs;h=436f3d29327de997b4522fc653e87431e2067a4f;hb=e2b15781f674220586e860fb9a85b6ad0f278fad;hp=c6ade9729042e4b22a6b3b6a7bba2334d4f09dad;hpb=ebd6d5f3f72d7fc7b5b0d7e17054373058cdf103;p=advent-of-code-21.git diff --git a/advent14/Main.hs b/advent14/Main.hs index c6ade97..436f3d2 100644 --- a/advent14/Main.hs +++ b/advent14/Main.hs @@ -1,4 +1,4 @@ --- Writeup at https://work.njae.me.uk/2021/12/13/advent-of-code-2021-day-13/ +-- Writeup at https://work.njae.me.uk/2021/12/16/advent-of-code-2021-day-14/ import Data.Text () import qualified Data.Text.IO as TIO @@ -60,13 +60,11 @@ addSecond rules pair = c ++ [a] where a = pair!!1 c = rules ! pair --- countElements :: PolyPairs -> MS.MultiSet Char countElements :: PolyPairs -> M.Map Char Int countElements pairs = counts where firsts = MS.map (!!0) pairs seconds = MS.map (!!1) pairs elems = S.union (MS.toSet firsts) (MS.toSet seconds) - -- counts = MS.fromMap $ M.map ((`div` 2) . (+ 1)) $ MS.toMap $ MS.union firsts seconds counts = M.map ((`div` 2) . (+ 1)) $ MS.toMap $ MS.union firsts seconds