From ad20b4a9ed09feb9907ac78479e35422faa5faf8 Mon Sep 17 00:00:00 2001 From: xenia Date: Mon, 11 Dec 2023 11:40:42 -0500 Subject: [PATCH] day 11: flop --- 11.rkt | 57 ++++++++++++++++++++ inputs/11 | 140 ++++++++++++++++++++++++++++++++++++++++++++++++ inputs/11-test1 | 10 ++++ 3 files changed, 207 insertions(+) create mode 100644 11.rkt create mode 100644 inputs/11 create mode 100644 inputs/11-test1 diff --git a/11.rkt b/11.rkt new file mode 100644 index 0000000..b8b5093 --- /dev/null +++ b/11.rkt @@ -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")) diff --git a/inputs/11 b/inputs/11 new file mode 100644 index 0000000..28b10c0 --- /dev/null +++ b/inputs/11 @@ -0,0 +1,140 @@ +.....#...............#......................................................................#.............................#..........#...... +........................................#............................#......#............................................................... +..............................#..............#....................................#..............................................#.......... +..............#........................................................................#.................................................... +..#...........................................................................................#............................................. +..................#.....................................#.....#......................................#.........#.......#.................... +...........#......................................#.....................#...........#................................................#...... +.............................#............................................................#.....................................#........... +.....#..................#.................#.........................#......................................#................................ +....................................#.................#........................#..........................................................#. +................#..............................#....................................................#....................................... +..............................................................#.........................#.......................#.....................#..... +............#...............#......................#.....................#..............................#................................... +......................................#...............................................................................#..................... +.........................................................#.................................................................................. +..............................................#............................................................................................. +..#.................#.....................................................................#.....#..........#..............#......#.......... +..............................................................................#............................................................. +..........................................#.........................#..............................................#........................ +.....#........#.............#...........................#...........................................#....................................... +..................................#...............#.............#.................#..........................#.....................#........ +.......................................................................#.................................................................... +...............................................................................................................................#.........#.. +#.......................................#....................................................#.........................#.................... +........#...............#....................................#...........................................#.................................. +...............................#............................................................................................................ +.........................................................#.................................................................................. +..#..........................................#........................................#.............#............................#.......... +......................#............................#.................#........#............................................................. +.........#.......#...........................................................................#.....................#.........#.........#.... +................................#............................................................................#.............................. +.........................................................................................#.................................................. +.#.........................................#.........#..........#.......................................................#................... +....................#.................#...............................................................#..................................... +............................................................................#............................................................... +........................#.........................................................................................#.................#....... +.............#.......................................................#......................................................#............... +.......#.................................#.....#..............................................................#............................. +#...............................#...............................................................#.....................#..................... +.....................................#...................#.......................#.....#.......................................#............ +..........................#.................#......#...................................................................................#.... +..............#............................................................................................................................. +...#..........................................................................#............................................#................ +.............................................................................................#.....................#......................#. +.......................................#..........................................................................................#......... +.......................................................................................................#.................................... +.....#.........#.................#.................#............#.........................#.................#............................... +............................#.....................................................#......................................................... +...........................................#................................................................................................ +....................................#.......................#.........................#............................#.....#.................. +............................................................................................................................................ +.....................#..................#................................#......#.....................................................#..... +.......................................................#.........#...............................#.....#.................................... +............#.................................................................................................................#............. +..............................................#..............#.......#.................................................#.................... +................................................................................................................#........................... +.........#.............................................................................#............#....................................... +.............................#...........................................#.....#............................................................ +.....#..........#.....#...........#.............#.....#.............................................................................#....... +...........................................#............................................................#.....#............................. +......................................#.........................#.........................#.....................................#........... +............................................................................................................................................ +.......#.....#.....#........................................#.................................#............................................. +.........................................#................................................................#.....#......#.................... +........................#.......#..................#.................................#.......................................#.......#...... +..............................................#............................................................................................. +...............................................................................#............................................................ +......................................................#..........#.......................................................................... +...#......#.................#.............#.............................#..........................#...............................#........ +.............................................................#........................#..........................#.........#................ +......................................#....................................................#.............................................#.. +............................................................................................................................................ +...............#......#.......................#.....#.......................................................#............................... +.#......#.......................#.........................#.......#....................................#.................................... +...............................................................................................#........................#......#.......#.... +............#...............#............#....................#........#..........#......................................................... +...............................................................................................................#............................ +..........................................................................................................#.................#............... +......................#........#.........................................................................................................#.. +....................................................................................#.....#.....#....................#...................... +.#.........#...............#........................................#...............................................................#....... +..................#......................................................#..........................#....................................... +.................................#.............#................................................................#.......#................... +........................#......................................................#..............#................................#............ +.....#..........................................................#.....#.................#..................................................# +.....................................#......#.........#...............................................#..................................... +............................................................................................................................................ +............................................................................................................................................ +.................................#..........................................#................#...................#..............#........... +.......#....................#............#.............................................#...................................#................ +..#................#........................................#.......#..............................#........................................ +........................#...........................................................................................................#....... +...........#..........................................#.........................#......................#.................................... +...........................................#................................................................................................ +......#...............................................................................#.........#........................................... +............................#.....................#................#........................................#...........#................... +..................#.........................................#............................................................................... +........................#...............#................................#.......#..............................#............#.............. +............#......................#.................#..................................................#..................................# +..#................................................................................................#........................................ +.........................................................................................................................#.................. +..................................................................#................................................#................#....... +.......#.....................................#.............................................................................................. +.................#...............#......#.....................#............................................................................. +....................................................................................#..................................#.................... +..............................................................................................#............#................................ +....#......................#................................................................................................................ +......................................................#.................................#..........................#.............#.......... +..........#.................................................................................................................#............... +.................................#..........#..................................#............................................................ +.......................................................................................................................................#.... +.......................................#..................................................................#......#.......................... +.............................#.........................................................#.......#............................................ +.........#....................................#............#.................................................................#.............. +...#...............................................................................#.................#...................................... +..................................................................................................................................#......... +....................#.............#...................................................................................#....................# +....................................................#...........#...........#............................................................... +.........................................................................................................#.................................. +..........#...............................#............................#.................................................................... +.............................................................#....................#.............................#..............#............ +.#...............#..........................................................................#..........................................#.... +............................#............................................................................................................... +............#......................................#............#..................................................................#........ +.......#...............................................................................................................#.................... +..................................#.......#..........................#........#...............#..........#....................#............. +....................#....................................#............................#..........................#.......................#.. +..............................................................#............................................................................. +..#............................#............................................................................#............................... +..............#.....................#...............................................................................................#....... +..........................#........................................#....................................#...........#....................... +..........................................#.................................#.................#............................................. +................................................#...........#..........#.....................................................#.............. +.........#.................................................................................................................................. +...................................................................................#............................#.......#................... +....#.............................#.............................#.......................................................................#... +.........................................#.........................................................#........................................ +....................#...........................................................................................................#........... +..............#........................................#..................................#...................#......................#...... +.........#.................#........................................#...........#........................................#.................. diff --git a/inputs/11-test1 b/inputs/11-test1 new file mode 100644 index 0000000..986aad4 --- /dev/null +++ b/inputs/11-test1 @@ -0,0 +1,10 @@ +...#...... +.......#.. +#......... +.......... +......#... +.#........ +.........# +.......... +.......#.. +#...#.....