Advertisement
Guest User

AOC day 22

a guest
Dec 30th, 2024
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. mkTotals :: [[(Key,Int)]] -> ST s [(Key,Int)]
  2. mkTotals prices = do
  3. totals <- newArray bounds 0 :: ST s (STArray s Key Int)
  4. forM_ prices
  5. (\price -> do
  6. checks <- newArray bounds False :: ST s (STArray s Key Bool)
  7. forM_ price
  8. (\(k,v) -> do
  9. check <- readArray checks k
  10. if check then
  11. return ()
  12. else do
  13. writeArray checks k True
  14. cv <- readArray totals k
  15. writeArray totals k (cv + v)))
  16. getAssocs totals
  17. where
  18. bounds = ((-9,-9,-9,-9), (9,9,9,9))
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement