Copyright | (c) Eric Mertens 2022 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
https://adventofcode.com/2022/day/14
>>>
:set -XQuasiQuotes
>>>
let input = [format|- ((%u,%u)&( -> )%n)*|] "498,4 -> 498,6 -> 496,6\n503,4 -> 502,4 -> 502,9 -> 494,9\n"
>>>
let world = Set.fromList (concatMap segs input)
>>>
let limit = voidLimit world
>>>
let Left world1 = fillFrom Left limit world top
>>>
let picture = Data.Map.fromSet (const '█') world <> Data.Map.fromSet (const '◆') world1
>>>
putStr (Advent.Coord.drawPicture picture)
······◆··· ·····◆◆◆·· ····█◆◆◆██ ···◆█◆◆◆█· ··███◆◆◆█· ····◆◆◆◆█· ·◆·◆◆◆◆◆█· █████████·>>>
Set.size world1 - Set.size world
24>>>
let Identity world2 = fillFrom Identity limit world top
>>>
let picture = Data.Map.fromSet (const '█') world <> Data.Map.fromSet (const '◆') world2
>>>
putStr (Advent.Coord.drawPicture picture)
··········◆·········· ·········◆◆◆········· ········◆◆◆◆◆········ ·······◆◆◆◆◆◆◆······· ······◆◆█◆◆◆██◆······ ·····◆◆◆█◆◆◆█◆◆◆····· ····◆◆███◆◆◆█◆◆◆◆···· ···◆◆◆◆·◆◆◆◆█◆◆◆◆◆··· ··◆◆◆◆◆◆◆◆◆◆█◆◆◆◆◆◆·· ·◆◆◆█████████◆◆◆◆◆◆◆· ◆◆◆◆◆·······◆◆◆◆◆◆◆◆◆>>>
Set.size world2 - Set.size world
93
Documentation
:: Monad m | |
=> (Set Coord -> m (Set Coord)) | behavior when sand reaches limit |
-> Int | lower limit |
-> Set Coord | initial wall and sand locations |
-> Coord | location to fill from |
-> m (Set Coord) | final wall and sand locations |
Fill the given world with sand from a fill coordinate returning the final state of the world. This is parameterized over a callback for how to handle when sand reaches the bottom of the level in order to allow early termination or not.