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

Main

Description

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

>>> :{
:main +
  "part 1 override 10 part 2 override 20\n\
  \Sensor at x=2, y=18: closest beacon is at x=-2, y=15\n\
  \Sensor at x=9, y=16: closest beacon is at x=10, y=16\n\
  \Sensor at x=13, y=2: closest beacon is at x=15, y=3\n\
  \Sensor at x=12, y=14: closest beacon is at x=10, y=16\n\
  \Sensor at x=10, y=20: closest beacon is at x=10, y=16\n\
  \Sensor at x=14, y=17: closest beacon is at x=10, y=16\n\
  \Sensor at x=8, y=7: closest beacon is at x=2, y=10\n\
  \Sensor at x=2, y=0: closest beacon is at x=2, y=10\n\
  \Sensor at x=0, y=11: closest beacon is at x=2, y=10\n\
  \Sensor at x=20, y=14: closest beacon is at x=25, y=17\n\
  \Sensor at x=17, y=20: closest beacon is at x=21, y=22\n\
  \Sensor at x=16, y=7: closest beacon is at x=15, y=3\n\
  \Sensor at x=14, y=3: closest beacon is at x=15, y=3\n\
  \Sensor at x=20, y=1: closest beacon is at x=15, y=3\n"
:}
26
56000011
Synopsis

Documentation

type Input = [(Int, Int, Int, Int)] Source #

Input is a list of: sensor x and y, beacon x and y

main :: IO () Source #

>>> :main
4724228
13622251246513

data Sensor Source #

A sensor has a location and a radius

Constructors

Sensor Coord Int 

inputSensors :: Input -> [(Sensor, Coord)] Source #

Convert input data into a list of sensors and beacon coordinates

part1 Source #

Arguments

:: Int

y value of row

-> [Sensor]

sensors

-> [Coord]

beacons

-> Int

locations in row that can't contain a sensor

Compute the number of locations in a given row that can't contain a sensor.

rowSlice Source #

Arguments

:: Int

y value

-> Sensor

sensor

-> [Box' 1]

bounds on x values

Generate the 1-d box describing the X region covered by the sensor at a given Y value

part2 Source #

Arguments

:: Int

search region size

-> [Sensor]

sensors

-> Int

tuning frequency

Find the tuning frequency of the only location in the given region that could contain an undiscovered beacon.

boxCorner :: Box' 2 -> Coord Source #

Find a corner of a diamond represented as a square region.

diamondBox :: Sensor -> Box' 2 Source #

Covert a diamond centered at a coordinate with a radius into a square region.

subtractAllOf Source #

Arguments

:: forall (n :: Nat). [Box n]

remove this

-> [Box n]

from this

-> [Box n]

remaining region

Remove the first list of regions from the second.

cover Source #

Arguments

:: forall (n :: Nat). Int

position

-> Int

radius

-> Box n 
-> Box ('S n) 

Extend a box to cover a new dimension centered on x with radius r.