diff options
| author | Tom Smeding <tom@tomsmeding.com> | 2026-12-03 20:57:54 +0100 |
|---|---|---|
| committer | Tom Smeding <tom@tomsmeding.com> | 2026-12-03 20:57:54 +0100 |
| commit | 8a6da5a43818f221104fa2a9049d54e445620718 (patch) | |
| tree | 1ae1d99dabfabc16ac386906818143bc9ae66644 /2026/2.hs | |
| parent | f914e5be6fd03bcdbb0defd3eefd9dba1501e2e6 (diff) | |
Diffstat (limited to '2026/2.hs')
| -rw-r--r-- | 2026/2.hs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/2026/2.hs b/2026/2.hs new file mode 100644 index 0000000..b05c400 --- /dev/null +++ b/2026/2.hs @@ -0,0 +1,19 @@ +{-# OPTIONS -Wno-x-partial -Wno-incomplete-uni-patterns #-} +module Main where + +import Control.Applicative (asum) +import Data.List (foldl', findIndex) +import Data.Map.Strict qualified as Map +import Data.Maybe (fromJust) + +main :: IO () +main = do + input <- head . words <$> getContents + let nexts i = drop ((i + 1) `rem` 6) (cycle "roygbv") + print $ foldl' (\i c -> i + 1 + fromJust (findIndex (==c) (nexts i))) 0 input + print . fst $ + foldl' (\(i, mp) _ -> + let Just (c', dist, n) = asum [(c,d,) <$> mp Map.!? c + | (c, d) <- zip (reverse (take 6 (nexts i))) [6,5..]] + in (i + dist, (if n > 1 then Map.adjust pred else Map.delete) c' mp)) + (0, Map.fromListWith (+) (map (,1::Int) input)) input |
