From 883cdcc79766ca224aef1704b0f08f5a79951b66 Mon Sep 17 00:00:00 2001 From: germax26 Date: Tue, 3 Dec 2024 07:10:01 +1100 Subject: [PATCH] 2015 Day 10 in Haskell --- 2015/day10/day10.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 2015/day10/day10.hs diff --git a/2015/day10/day10.hs b/2015/day10/day10.hs new file mode 100644 index 0000000..0d750cd --- /dev/null +++ b/2015/day10/day10.hs @@ -0,0 +1,14 @@ +import Aoc +import Data.List ( group, sort ) + +step :: String -> String +step = concat . concatMap (\cs -> [show $ length cs, [head cs]]) . group + +part1 :: String -> (Int, String) +part1 x = (length after40, after40) + where after40 = iterate step x !! 40 + +part2 :: p -> String -> Int +part2 _ after40 = length (iterate step after40 !! 10) -- only 10 more needed + +main = aocMain' single part1 part2 \ No newline at end of file