Advent of Code 2025
1module Day2 where
2
3import Debug.Trace
4import Util
5
6isPartOneCandidate :: Int -> Bool
7isPartOneCandidate n =
8 let s = show n
9 d = length s
10 in take (d `div` 2) s == drop (d `div` 2) s
11
12isPartTwoCandidate :: Int -> Bool
13isPartTwoCandidate n =
14 let s = show n
15 d = length s
16 cands = [concat $ replicate k $ take (d `div` k) s | k <- [2..d]]
17 in any (== s) cands
18
19parseEntry :: [String] -> (Int, Int)
20parseEntry (a : b : _) = (read a, read b)
21parseEntry _ = error "Unreachable "
22
23parse :: String -> [(Int, Int)]
24parse s =
25 map (parseEntry . split '-') $
26 split ',' s
27
28part1 :: String -> String
29part1 input = show $
30 sum $
31 filter isPartOneCandidate $
32 concat $
33 map (\(a,b) -> [a..b]) $
34 parse input
35
36part2 :: String -> String
37part2 input = show $
38 sum $
39 filter isPartTwoCandidate $
40 concat $
41 map (\(a,b) -> [a..b]) $
42 parse input