AoC/2019/day4/day4.hs
2019-12-04 08:21:27 +01:00

24 lines
494 B
Haskell

import Data.List
main = do
print (day4a 130254 678275)
print (day4b 130254 678275)
day4a bottom top = dumbbrute bottom top p 0
day4b bottom top = dumbbrute bottom top p' 0
dumbbrute x y p acc
| x'<=y = dumbbrute x' y p (if p $ show x then acc+1 else acc)
| otherwise = acc
where x' = succ x
p x
| sort x /= x = False
| nub x == x = False
| otherwise = True
p' x
| sort x /= x = False
| 2 `elem` (map length $ group x) = True
| otherwise = False