1 -- Writeup at https://work.njae.me.uk/2022/12/06/advent-of-code-2022-day-6/
6 -- test = "mjqjpqmgbljsphdztnvjfqwrcgsmlb"
10 do dataFileName <- getDataFileName
11 text <- readFile dataFileName
17 part1 :: String -> Int
18 part1 = interestingPosition 4
20 part2 :: String -> Int
21 part2 = interestingPosition 14
23 interestingPosition :: Int -> String -> Int
24 interestingPosition n text = n + (fst packetPos)
25 where candidates = zip [0..] $ fmap (take n) $ tails text
26 packetPos = head $ dropWhile (hasSame . snd) candidates
28 allDifferent, hasSame :: String -> Bool
29 allDifferent cs = nub cs == cs
30 hasSame = not . allDifferent