My solutions to Advent of Code 2021
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

47 lines
1.1 KiB

  1. module Main where
  2. main :: IO ()
  3. main = interact solution
  4. type Board = [[Int]]
  5. type BoardMask = [[Bool]]
  6. scnd :: (b -> c) -> (a, b) -> (a, c)
  7. scnd f (a, b) = (a, f b)
  8. frst :: (a -> c) -> (a, b) -> (c, b)
  9. frst f (a, b) = (f a, b)
  10. solution :: String -> String
  11. solution =
  12. show
  13. -- ([Int], [Boards])
  14. . scnd toBoards
  15. . scnd (map (map (read :: String -> Int)))
  16. . scnd (filter (not . null))
  17. . scnd (map words)
  18. . frst (map (read :: String -> Int))
  19. . frst splitcomma
  20. . (\x -> (head x, tail x))
  21. . lines
  22. where
  23. splitcomma :: String -> [String] -- "stole" the implementation from `words`
  24. splitcomma s = case dropWhile (==',') s of
  25. "" -> []
  26. s' -> w : splitcomma s''
  27. where
  28. (w, s'') = break (==',') s'
  29. toBoards :: [[Int]] -> [Board]
  30. toBoards [] = []
  31. toBoards (a:b:c:d:e:r) = [a,b,c,d,e]:toBoards r
  32. calculateScore :: Int -> -- ^ winning number
  33. Board -> -- ^ winning board
  34. BoardMask -> -- ^ drawn numbers
  35. Int
  36. calculateScore = undefined
  37. checkWinning :: BoardMask -> Bool
  38. checkWinning = undefined