Copyright | (c) Eric Mertens 2022 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
https://adventofcode.com/2022/day/17
This solution looks for cycles when the move index, piece index, and tower envelope repeat. The tower envelope is the set of rocks that are reachable from the row above the top of the tower.
>>>
:main + ">>><<><>><<<>><>>><<<>>><<<><<<>><>><<>>\n"
3068 1514285714288
Synopsis
- pieces :: Array Int (Set Coord)
- initialStuff :: Set Coord
- main :: IO ()
- height :: Set Coord -> Int
- normalize :: Set Coord -> Set Coord
- findCycle :: Ord a => [a] -> (Int, Int)
- dir :: Char -> Coord
- inWalls :: Coord -> Bool
- translate :: Set Coord -> Coord -> Set Coord
- clean :: Set Coord -> Set Coord
- place :: Array Int Coord -> (Int, Int, Set Coord) -> (Int, Int, Set Coord)
Documentation
pieces :: Array Int (Set Coord) Source #
The set of five blocks
>>>
mapM_ (putStrLn . Advent.Coord.drawCoords) pieces
████ ·█· █·█ ·█· ··█ ··█ ███ █ █ █ █ ██ ██
initialStuff :: Set Coord Source #
The initial floor
findCycle :: Ord a => [a] -> (Int, Int) Source #
Returns two indexes showing where a cycle starts and ends
clean :: Set Coord -> Set Coord Source #
Remove all blocks that aren't reachable from the top of the board
:: Array Int Coord | jet vectors |
-> (Int, Int, Set Coord) | piece index, jet index, rocks |
-> (Int, Int, Set Coord) | piece index, jet index, rocks |
Piece the next piece on the top of the tower returning the updated piece index, jet index, and tower contents. The tower is pruned to exclude all rocks that are not reachable from the top of the tower.