summaryrefslogtreecommitdiff
path: root/2026
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2026-12-03 20:57:54 +0100
committerTom Smeding <tom@tomsmeding.com>2026-12-03 20:57:54 +0100
commit8a6da5a43818f221104fa2a9049d54e445620718 (patch)
tree1ae1d99dabfabc16ac386906818143bc9ae66644 /2026
parentf914e5be6fd03bcdbb0defd3eefd9dba1501e2e6 (diff)
Diffstat (limited to '2026')
-rw-r--r--2026/2.hs19
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