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

Main

Description

https://adventofcode.com/2022/day/23

>>> :{
:main +
  ".......#......\n\
  \.....###.#....\n\
  \...#...#.#....\n\
  \....#...##....\n\
  \...#.###......\n\
  \...##.#.##....\n\
  \....#..#......\n"
:}
110
20
Synopsis

Documentation

main :: IO () Source #

>>> :main
4236
1023

sim :: Set Coord -> [Set Coord] Source #

Generate an infinite list of the rounds of the elf movement rules

step Source #

Arguments

:: Set Coord

initial elf locations

-> (UArray Coord Bool -> Coord -> Maybe Coord)

proposal rule

-> Set Coord

final elf locations

Apply a single round of the elf movement rules

isCrowded :: CoordSet -> Coord -> Bool Source #

Predicate testing to see if elf is near any other elf.

moveSets :: [(Coord -> Coord, Coord -> Coord, Coord -> Coord)] Source #

Move directions and their neighbors in the priority order of round 1

sameIx :: Ord a => [a] -> Maybe Int Source #

Find index in list where element is the same as the previous element.

subtractFromSet :: (Foldable f, Ord a) => Set a -> f a -> Set a Source #

type CoordSet = UArray Coord Bool Source #

A set of coordinates represented with an array for fast membership lookups

coordSet :: Set Coord -> CoordSet Source #

Build an array-based representation of the set of coordinates. Because our elves are densely packed, and we do lots of membership tests, this representation is more efficient.

arrayMember :: CoordSet -> Coord -> Bool Source #

Membership operation for CoordSet