about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2022-12-24 14:49:53 +0100
committerLeah Neukirchen <leah@vuxu.org>2022-12-24 14:49:53 +0100
commitd04167bb02ebfcb10192724fc0e9204ea23fb199 (patch)
tree71be65faee7398761ca9ac04319524c57344f8d9
parent4afb3d46af70a0a0628b159f71da58692c21a17b (diff)
downloadadventofcode2022-d04167bb02ebfcb10192724fc0e9204ea23fb199.tar.gz
adventofcode2022-d04167bb02ebfcb10192724fc0e9204ea23fb199.tar.xz
adventofcode2022-d04167bb02ebfcb10192724fc0e9204ea23fb199.zip
day23
-rw-r--r--day2371
-rw-r--r--day23.rkt70
2 files changed, 141 insertions, 0 deletions
diff --git a/day23 b/day23
new file mode 100644
index 0000000..e25be94
--- /dev/null
+++ b/day23
@@ -0,0 +1,71 @@
+#.##..##.#..#.##..##....##..#..#####...#.###.#..##..#..#.#...##..##....
+##..###.#.#.#..##.##.####.........#...#..#..#.#..#.#....##..###.#.##..#
+#.......###....#.#.##.#.#.#.##..###...###..##.....#...#.##.##.......##.
+...##.#......#.#.#..#.###..#.###....#....#.###.##....####....##....##..
+.#...##..###...##.#.#..#...####.#.##.#.#..#.##.###.###.#.##.##..#.#...#
+#..##....##.#..##.##...###..##.#...##...#####...#####.##..#.###....#.#.
+###....#....#.##.####.###.#..####..##..##..#..#.##.#######.##....###...
+###..###.....###..##..##....#......#.#.##...####.######..###.###....###
+#.#.###.###.....###.####.#.####...#.#.###.#...#.##..##.##.#..####..#...
+####.##...#....##.##.#.#....##.###....#.#..#.....##...##.#...###.##.#.#
+...#.#..####.###...###.#....###...##.####..#.######.##.##..#.#..##...#.
+#####......#.####.#####...#...#..#..#.#.#.#.#.#.#.#.##.#..#.###.#....#.
+#..#.#.#..#...#.#.##..#.######.##..#.###...#.#.#...#.####..##..##..#.#.
+..#.#..###....#.##.##....####.#########..#.########..##....#..#..##..#.
+.#.#.#...##...##.#.#..#..#####..###....#..#...####.##.####.###.##..##..
+.##.####..#.#######..#.#######..##..###....#.#..#..##.#..#.#..###.....#
+#....#.#####..#.##...###.###....#.#.#.#..#.##.####...#...##..#####.##..
+...##.###.##...#.##.###.#.###....####.....#.##.##.##.###...###.###.#.##
+..###...#...##....#.###.....##..####..#.###.####..##.###....##.#....##.
+...#..##..#..##.###.#....###....#..##..#...##.#..##.#.####...##.##..###
+######.......####..#..#.#####.......#####..#.#..##..#......#.#.#.#####.
+.#...#..#.##.###..#.#.#..####.#.########.#.###..####.#..#.#..###.#####.
+...####.#..#..#.##...#.#####.########.##..##....#####.#.##..######.#.##
+.....#..##.#.....#..#.#.##..######..####.#..#....##.....###.#.#..##..#.
+..##.##..##.#.#.##...##.##...#..##.....#..#..#.#.#.....#.#.##.###...###
+##.#..#.#.####.##....#...##.#...#...#..#.##..#...##.....#.#.##.#####...
+...#..##..##...#..###....#..#.###..####...#.#..##.###.##......###.#.#.#
+..##.#.#.##..###.....#..##.#....#....#....#.##..#.#.####.#....##..#..##
+.##..##..#.#.....###..#.#..#.##.#.#.#..#..#.##.#.###...#..#..##.#....##
+......#...######....###.##..#.###.####.##.##...#.###...####.##..#..#...
+#..##.#.###.##......####...#.#.##.#.#....##.##..#.#.....####...#..###..
+..##...#.##..#.....#######.#.#.###.#.##...####..#.#....##.###..##.#.###
+...####..#..##.########..#####.##..##...#..##..##..#...###.###....#.###
+.###.#..#.##.#..###.#.##.#.#...#.#.#.##..##.#....###.#..#.....#..##..#.
+...##.##...#..#.####.....#.##....####.#.###..##...#..#.####...##..##.##
+###...##....##..##.#...##......#...##.##.#.....##..##.#..#.##......#..#
+.......#.######...#####....#...#####.#####...##..#..#.#.#..........#.#.
+#######.#...#.#..#..#..##..#.####..#.##..###..###.##.#...#.#..#.####.##
+.#..#......#.#....###.#..##..####.#..#.#..##..#####.#....##.#####.#.#.#
+.#.###.###..#..#.#.#.#..##.#......###.##.#....#######.#..#.#####.....##
+#.####..###.#..###.#.#...##.##....###.#.#.#.###..#...#...#.##.###...#..
+#..##..##.##..##....###..######....#.#####.##..#...#....#.#.###.###....
+#.###..##.##..#.....##...#..#..#####.#.##..##..#.#...#.....##.#..#.##.#
+##...#...#.##..####..#..#.###....#...#.....#.#.#.###...###...#####.#.##
+.#.###.....#.#..#.###########.######..#########.##.##..#.#.#...#..##.##
+##.#################.#.##.##....####.....#..#.#.##.###.##..#..#.##..#.#
+.##.####.#.#..##.##.#.#..#.###.#..#..#.####....#.###.####.#.#..##..####
+##....###.#.####.#.#.............##.....###.##.#.###.####...#####.##.#.
+...##.#.#.#####.####.##.#..##.###.###.####.#.#.....#.#.#...#####..####.
+######.#....#...#.#.######.#.#....#.##..#..#..#..#.......#..#.##.#.#...
+...#..#....#.#.#...###.####..##.#.#..#.#.#.####.#..###...###.######...#
+#.#.###......##...#...##....###......#.###...#...###..#..####..##...#.#
+#..##.....#........###.##..#.#.#.#.##..#.##.#..###.##.#.####..###.##.#.
+.##....#..##.###.#.#.#..#..###..#..#####.##....#..#####.#.##..#.##.###.
+.#.##.###.####.#.#..#.###.###.#.......####.##...#..##.#.##.##..#.###...
+#.##...#####.#...#.#.##..###.#.##.###########..#...#..#.#.###.#.##..#.#
+##...#...#.###.#..##..#...##....#...#.#....###.###.#.#..#...#.#.#.#.###
+#.#.######.##.#....#.....#..##...#.#####...##.##...#..###.#...##.#..##.
+##.#######.....#....#.###..#..#.###.###..#.....####....#.####..#.....#.
+#..#..##..##.#.##......#....#.#.....#......#...##.###..#.#.###.......##
+#..#.#..######.#.......##..#...#....#####.#...#.##...#...###..####.##..
+.....#.....#.#.##..###.###.##..#.##.##..#.#####..##.##..###..###..#.###
+...#.###.#.#.#.##...##.##...#..#..#..####.#.##.#...#.#..##.#.#######.##
+.####.####..#.####...#...#.#..##...##.##..#....#.#.###.###..#####...##.
+..##.#.###.####.#####...#......#.#.###...###..##.##.###.####.###.#..#.#
+#.##..####.#.#..#.##..#.##.#.##.#..###.####.#.#.#.##..#.....##.#.#...#.
+.##...#.#.#####.###.#...###.#......#####.....#.#######.##.#..##...###..
+##.#.#####......####.####...#####....#..####.#.#.####...####.###.###.##
+#.#.#.####..##.##.##.#.##.#.#####.##...#....##..##...#.######.....#..##
+.#.....#...###.#.#.###.#..#...###...##.......####...####.###..#....#...
+..##.##..#......###...##.....##.#..#...###.##.#.##.##...#.#...#.#..#...
diff --git a/day23.rkt b/day23.rkt
new file mode 100644
index 0000000..02e6550
--- /dev/null
+++ b/day23.rkt
@@ -0,0 +1,70 @@
+#lang racket
+
+(define occupied
+  (list->mutable-set
+   (for*/list ([(line row) (in-indexed (file->lines "day23"))]
+               [(char col) (in-indexed line)]
+               #:when (equal? char #\#))
+     (vector col row))))
+
+; (set-count occupied)
+; occupied
+
+(define adjs (list (list #(0 -1) #(1 -1) #(-1 -1))
+                   (list #(0  1) #(1  1) #(-1  1))
+                   (list #(-1 0) #(-1 1) #(-1 -1))
+                   (list #( 1 0) #( 1 1) #( 1 -1))))
+(define dirs (list #(0 -1)
+                   #(0  1)
+                   #(-1 0)
+                   #( 1 0)))
+
+(let loop ((rounds 1))
+  (define next (make-hash))
+  (for ([elf occupied])
+    (unless (for*/and ([dx '(-1 0 1)]
+                       [dy '(-1 0 1)]
+                       #:unless (= dx dy 0))
+              (not (set-member? occupied (vector-map + elf (vector dx dy)))))
+      (for/or ([adj adjs]
+               [dir dirs])
+        (if (for/and ([p adj])
+              (not (set-member? occupied (vector-map + elf p))))
+          (begin
+            (hash-update! next
+                          (vector-map + elf dir)
+                          (lambda (l) (cons elf l))
+                          '())
+            #t)                         ;; break
+          #f))))
+
+  (set! adjs (append (cdr adjs) (list (car adjs))))
+  (set! dirs (append (cdr dirs) (list (car dirs))))
+
+  (define moved #f)
+  (for ([(cand elf) next])
+    (when (= (length elf) 1)
+      (set-remove! occupied (first elf))
+      (set-add! occupied cand)
+      (set! moved #t)))
+
+  (when (= rounds 10)
+    (displayln (for/fold ([min-x  9999]
+                          [max-x -9999]
+                          [min-y  9999]
+                          [max-y -9999]
+                          #:result (- (* (- max-x min-x -1)
+                                         (- max-y min-y -1))
+                                      (set-count occupied))
+                          )
+                   ([elf occupied])
+                 (values (min min-x (vector-ref elf 0))
+                         (max max-x (vector-ref elf 0))
+                         (min min-y (vector-ref elf 1))
+                         (max max-y (vector-ref elf 1))))))
+  ;; 3940
+
+  (if moved 
+    (loop (+ rounds 1))
+    (displayln rounds)))
+;; 990