| Copyright | (c) Eric Mertens 2022 |
|---|---|
| License | ISC |
| Maintainer | emertens@gmail.com |
| Safe Haskell | None |
| Language | Haskell2010 |
Main
Description
https://adventofcode.com/2022/day/9
>>>:{:main + "R 4\n\ \U 4\n\ \L 3\n\ \D 1\n\ \R 4\n\ \D 1\n\ \L 5\n\ \R 2\n" :} 13 1
>>>:{:main + "R 5\n\ \U 8\n\ \L 8\n\ \D 3\n\ \R 17\n\ \D 10\n\ \L 25\n\ \U 20\n" :} 88 36
>>>uniqueLocations [(CR,4),(CU,4),(CL,3),(CD,1),(CR,4),(CD,1),(CL,5),(CR,2)] !! 113
>>>uniqueLocations [(CR,5),(CU,8),(CL,8),(CD,3),(CR,17),(CD,10),(CL,25),(CU,20)] !! 936
Documentation
Rope movement instructions
Print the answers to both parts of day 9. Automatically finds input file unless overridden with a command line argument.
>>>:main5930 2443
uniqueLocations :: [(C, Int)] -> [Int] Source #
Generate the number of unique locations each knot in an infinitely long rope visits given a list of movement commands.
Update all the knot locations in a rope given a step direction for the head knot.
Update all the tail knots in the rope given a new head position.
isNearOrigin :: Coord -> Bool Source #
Predicate for coordinates at or adjacent to the origin.
>>>all isNearOrigin [C y x | y <- [-1..1], x <- [-1..1]]True
>>>any isNearOrigin [C 2 0, C 0 2, C 2 1, C (-2) 0, C (-1) 2]False
countUnique :: Ord a => [a] -> Int Source #
Return the number of unique elements in a list.