sln_2022_17
Copyright(c) Eric Mertens 2022
LicenseISC
Maintaineremertens@gmail.com
Safe HaskellNone
LanguageHaskell2010

Main

Description

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

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

main :: IO () Source #

>>> :main
3137
1564705882327

height :: Set Coord -> Int Source #

Height of a tower

normalize :: Set Coord -> Set Coord Source #

Renumber a tower so that it's top starts at 0

findCycle :: Ord a => [a] -> (Int, Int) Source #

Returns two indexes showing where a cycle starts and ends

dir :: Char -> Coord Source #

Map the input characters to jet vectors

inWalls :: Coord -> Bool Source #

Predicate for coordinates that are inside the tower walls

translate :: Set Coord -> Coord -> Set Coord Source #

Translate a piece around by a vector

clean :: Set Coord -> Set Coord Source #

Remove all blocks that aren't reachable from the top of the board

place Source #

Arguments

:: 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.