day 11: flop

This commit is contained in:
xenia 2023-12-11 11:40:42 -05:00
parent b9ec918dd5
commit ad20b4a9ed
3 changed files with 207 additions and 0 deletions

57
11.rkt Normal file
View File

@ -0,0 +1,57 @@
#lang curly-fn racket
(require "scripts/aoc.rkt")
;; solution for day 11
(define (expand universe [amount 1])
(define width
(add1 (apply max (set-map universe car))))
(define height
(add1 (apply max (set-map universe cdr))))
(define (has-y? y)
(for/or ([pt (in-set universe)])
(= (cdr pt) y)))
(define (has-x? x)
(for/or ([pt (in-set universe)])
(= (car pt) x)))
(define empty-rows
(for/list ([y (in-range height)]
#:unless (has-y? y))
y))
(define empty-cols
(for/list ([x (in-range width)]
#:unless (has-x? x))
x))
(for/set ([pt (in-set universe)])
(define x-offset (count #{< % (car pt)} empty-cols))
(define y-offset (count #{< % (cdr pt)} empty-rows))
(cons (+ (car pt) (* amount x-offset)) (+ (cdr pt) (* amount y-offset)))))
(define (part1 input [amount 1])
(define expanded (expand input amount))
(/ (for*/sum ([a (in-set expanded)] [b (in-set expanded)])
(+ (abs (- (car a) (car b)))
(abs (- (cdr a) (cdr b)))))
2))
(define (part2 input)
(part1 input (sub1 1000000)))
(define (parse fname)
(for/set ([line (in-list (file->lines fname))] [y (in-naturals)]
#:do []
[char (in-string line)] [x (in-naturals)]
#:when (eq? char #\#))
(cons x y)))
(module+ main
(define input (parse "inputs/11"))
(answer 11 1 (time (part1 input)))
(answer 11 2 (time (part2 input)))
(displayln "meow"))

140
inputs/11 Normal file
View File

@ -0,0 +1,140 @@
.....#...............#......................................................................#.............................#..........#......
........................................#............................#......#...............................................................
..............................#..............#....................................#..............................................#..........
..............#........................................................................#....................................................
..#...........................................................................................#.............................................
..................#.....................................#.....#......................................#.........#.......#....................
...........#......................................#.....................#...........#................................................#......
.............................#............................................................#.....................................#...........
.....#..................#.................#.........................#......................................#................................
....................................#.................#........................#..........................................................#.
................#..............................#....................................................#.......................................
..............................................................#.........................#.......................#.....................#.....
............#...............#......................#.....................#..............................#...................................
......................................#...............................................................................#.....................
.........................................................#..................................................................................
..............................................#.............................................................................................
..#.................#.....................................................................#.....#..........#..............#......#..........
..............................................................................#.............................................................
..........................................#.........................#..............................................#........................
.....#........#.............#...........................#...........................................#.......................................
..................................#...............#.............#.................#..........................#.....................#........
.......................................................................#....................................................................
...............................................................................................................................#.........#..
#.......................................#....................................................#.........................#....................
........#...............#....................................#...........................................#..................................
...............................#............................................................................................................
.........................................................#..................................................................................
..#..........................................#........................................#.............#............................#..........
......................#............................#.................#........#.............................................................
.........#.......#...........................................................................#.....................#.........#.........#....
................................#............................................................................#..............................
.........................................................................................#..................................................
.#.........................................#.........#..........#.......................................................#...................
....................#.................#...............................................................#.....................................
............................................................................#...............................................................
........................#.........................................................................................#.................#.......
.............#.......................................................#......................................................#...............
.......#.................................#.....#..............................................................#.............................
#...............................#...............................................................#.....................#.....................
.....................................#...................#.......................#.....#.......................................#............
..........................#.................#......#...................................................................................#....
..............#.............................................................................................................................
...#..........................................................................#............................................#................
.............................................................................................#.....................#......................#.
.......................................#..........................................................................................#.........
.......................................................................................................#....................................
.....#.........#.................#.................#............#.........................#.................#...............................
............................#.....................................................#.........................................................
...........................................#................................................................................................
....................................#.......................#.........................#............................#.....#..................
............................................................................................................................................
.....................#..................#................................#......#.....................................................#.....
.......................................................#.........#...............................#.....#....................................
............#.................................................................................................................#.............
..............................................#..............#.......#.................................................#....................
................................................................................................................#...........................
.........#.............................................................................#............#.......................................
.............................#...........................................#.....#............................................................
.....#..........#.....#...........#.............#.....#.............................................................................#.......
...........................................#............................................................#.....#.............................
......................................#.........................#.........................#.....................................#...........
............................................................................................................................................
.......#.....#.....#........................................#.................................#.............................................
.........................................#................................................................#.....#......#....................
........................#.......#..................#.................................#.......................................#.......#......
..............................................#.............................................................................................
...............................................................................#............................................................
......................................................#..........#..........................................................................
...#......#.................#.............#.............................#..........................#...............................#........
.............................................................#........................#..........................#.........#................
......................................#....................................................#.............................................#..
............................................................................................................................................
...............#......#.......................#.....#.......................................................#...............................
.#......#.......................#.........................#.......#....................................#....................................
...............................................................................................#........................#......#.......#....
............#...............#............#....................#........#..........#.........................................................
...............................................................................................................#............................
..........................................................................................................#.................#...............
......................#........#.........................................................................................................#..
....................................................................................#.....#.....#....................#......................
.#.........#...............#........................................#...............................................................#.......
..................#......................................................#..........................#.......................................
.................................#.............#................................................................#.......#...................
........................#......................................................#..............#................................#............
.....#..........................................................#.....#.................#..................................................#
.....................................#......#.........#...............................................#.....................................
............................................................................................................................................
............................................................................................................................................
.................................#..........................................#................#...................#..............#...........
.......#....................#............#.............................................#...................................#................
..#................#........................................#.......#..............................#........................................
........................#...........................................................................................................#.......
...........#..........................................#.........................#......................#....................................
...........................................#................................................................................................
......#...............................................................................#.........#...........................................
............................#.....................#................#........................................#...........#...................
..................#.........................................#...............................................................................
........................#...............#................................#.......#..............................#............#..............
............#......................#.................#..................................................#..................................#
..#................................................................................................#........................................
.........................................................................................................................#..................
..................................................................#................................................#................#.......
.......#.....................................#..............................................................................................
.................#...............#......#.....................#.............................................................................
....................................................................................#..................................#....................
..............................................................................................#............#................................
....#......................#................................................................................................................
......................................................#.................................#..........................#.............#..........
..........#.................................................................................................................#...............
.................................#..........#..................................#............................................................
.......................................................................................................................................#....
.......................................#..................................................................#......#..........................
.............................#.........................................................#.......#............................................
.........#....................................#............#.................................................................#..............
...#...............................................................................#.................#......................................
..................................................................................................................................#.........
....................#.............#...................................................................................#....................#
....................................................#...........#...........#...............................................................
.........................................................................................................#..................................
..........#...............................#............................#....................................................................
.............................................................#....................#.............................#..............#............
.#...............#..........................................................................#..........................................#....
............................#...............................................................................................................
............#......................................#............#..................................................................#........
.......#...............................................................................................................#....................
..................................#.......#..........................#........#...............#..........#....................#.............
....................#....................................#............................#..........................#.......................#..
..............................................................#.............................................................................
..#............................#............................................................................#...............................
..............#.....................#...............................................................................................#.......
..........................#........................................#....................................#...........#.......................
..........................................#.................................#.................#.............................................
................................................#...........#..........#.....................................................#..............
.........#..................................................................................................................................
...................................................................................#............................#.......#...................
....#.............................#.............................#.......................................................................#...
.........................................#.........................................................#........................................
....................#...........................................................................................................#...........
..............#........................................#..................................#...................#......................#......
.........#.................#........................................#...........#........................................#..................

10
inputs/11-test1 Normal file
View File

@ -0,0 +1,10 @@
...#......
.......#..
#.........
..........
......#...
.#........
.........#
..........
.......#..
#...#.....