commit - 1af7fd644bbac6ad0c08078a59d37b095fbeca10
commit + db13595fbfe221cdbdfbe5dd8134ed28f25c8f71
blob - /dev/null
blob + 1abb456d02f74bdb790a8455d5af61fca263ef9c (mode 644)
--- /dev/null
+++ input/8.txt
+....................................8.............
+..................E...............................
+.................................g................
+...........................................l...b..
+..C...........s..............8..........b.........
+..................3..1........................b...
+............N....3.....................1.....b....
+.....................N.....8....1..............2..
+..q....................................P..........
+......................N...........................
+...........E.................................l....
+.............S.....c.............T..2v............
+.........w....E........q............L.....P.....l.
+........w..............................a...V......
+...........t..................v..V................
+.....w.C............................V....4.....L..
+........................................I.n..T....
+.....E.5..C...8....3..q...........................
+...............s..0...A........W...........a....T.
+...............A................vPT...L..W..e.4...
+...........Cw..................2.....G.p.....4....
+....S........q........s.............a.............
+S.............c......e....................V.......
+......5...........................................
+....5.............................................
+...........................I............g.........
+...............c.........A........................
+.................s.............G.............etg..
+.........5...L.........f...v......W...............
+............................0.W.....I........t....
+..................................................
+...................f...........Q.0................
+..............1m9.f..........0........3.........F.
+..f...9................B..........................
+...........S...........................F......e...
+........c.............n.....Q.....................
+.....N...............B............g..7....t.......
+..........B.........P.......G.....................
+..m...........................Q...................
+.............m.....................p...........F..
+.....M..B......Q..i.....................7.4.......
+............M..................7..................
+...........n......................................
+................................p.....6.F.7.......
+..........M...........p.........6.................
+.M............i...................................
+..............................G...................
+..............li.......................6..........
+.....9.....................i...6..................
+.....n.............................9..............
blob - /dev/null
blob + 670b5a3f380679f41ef210bba2c155a6ad12cc38 (mode 644)
--- /dev/null
+++ src/day-8.lisp
+(defpackage #:aoc/day-8
+ (:use #:cl #:aoc/utils)
+ (:export #:day-8))
+(in-package #:aoc/day-8)
+
+(defun find-antennas (map)
+ (loop with antennas = (make-hash-table)
+ for x from 0 below (input-map-width map)
+ do (loop for y from 0 below (input-map-height map)
+ for point = (cons x y)
+ for cell = (map-cell map point)
+ unless (char= cell #\.)
+ do (setf (gethash cell antennas)
+ (cons point (gethash cell antennas))))
+ finally (return antennas)))
+
+(defun antinode-location (location-1 location-2)
+ (when (equal location-1 location-2)
+ (return-from antinode-location nil))
+ (point+ location-1 (point- location-1 location-2)))
+
+(defun antinode-locations (location-1 location-2 width height)
+ (when (equal location-1 location-2)
+ (return-from antinode-locations nil))
+ (loop with diff = (point- location-1 location-2)
+ for point = (point+ (or point location-1) diff)
+ while (point-in-bounds-p point width height)
+ collect point))
+
+(defun compute-antinodes (map antennas)
+ (loop with antinodes-task-1 = (make-hash-table :test #'equal)
+ with antinodes-task-2 = (make-hash-table :test #'equal)
+ with map-width = (input-map-width map)
+ with map-height = (input-map-height map)
+ for antenna-locations being the hash-values of antennas
+ do (loop for location-1 in antenna-locations
+ do (setf (gethash location-1 antinodes-task-2) t)
+ do (loop for location-2 in antenna-locations
+ for antinode-task-1 = (antinode-location location-1 location-2)
+ when (and antinode-task-1
+ (point-in-bounds-p antinode-task-1 map-width map-height))
+ do (setf (gethash antinode-task-1 antinodes-task-1) t)
+ do (loop for antinode-task-2 in (antinode-locations location-1
+ location-2
+ map-width
+ map-height)
+ do (setf (gethash antinode-task-2 antinodes-task-2) t))))
+ finally (return (values (hash-table-count antinodes-task-1)
+ (hash-table-count antinodes-task-2)))))
+
+(defun day-8 (input)
+ (let* ((map (make-map input))
+ (antennas (find-antennas map)))
+ (compute-antinodes map antennas)))
blob - /dev/null
blob + 3e8a81974017dd0e49f40c6ae0442c1fb3834f42 (mode 644)
--- /dev/null
+++ t/day-8.lisp
+(defpackage #:aoc-test/day-8
+ (:use #:cl #:lisp-unit2)
+ (:import-from #:aoc/day-8))
+(in-package #:aoc-test/day-8)
+
+(define-test test-day-8
+ ()
+ (multiple-value-bind (task-1 task-2)
+ (aoc:run-day 8 "............
+........0...
+.....0......
+.......0....
+....0.......
+......A.....
+............
+............
+........A...
+.........A..
+............
+............")
+ (assert= 14 task-1)
+ (assert= 34 task-2)))