diff options
author | Hunky Jimpjorps <thechairman@thechairman.info> | 2022-11-26 01:43:33 -0500 |
---|---|---|
committer | Hunky Jimpjorps <thechairman@thechairman.info> | 2022-11-26 01:43:33 -0500 |
commit | feccf3f6f0a806b3317d1f399e3e8b42945c4f09 (patch) | |
tree | bf15ce045d1106c1b7f7de30c27540f40d0bf947 /2021/day-19 | |
parent | 8b624fe7d2751337b1f16830cc9c041df73e99e7 (diff) | |
download | gleam_aoc-feccf3f6f0a806b3317d1f399e3e8b42945c4f09.tar.gz gleam_aoc-feccf3f6f0a806b3317d1f399e3e8b42945c4f09.zip |
using raco fmt, replacing missing dependency
Diffstat (limited to '2021/day-19')
-rw-r--r-- | 2021/day-19/day-19.rkt | 44 |
1 files changed, 14 insertions, 30 deletions
diff --git a/2021/day-19/day-19.rkt b/2021/day-19/day-19.rkt index b05c56b..4c6334d 100644 --- a/2021/day-19/day-19.rkt +++ b/2021/day-19/day-19.rkt @@ -1,6 +1,5 @@ #lang racket (require "../../jj-aoc.rkt" - awesome-list threading racket/struct) @@ -12,10 +11,7 @@ (coord (f x1 x2) (f y1 y2) (f z1 z2))) (define (coord-reduce f c1 c2) - (foldl (λ (i1 i2 acc) (+ acc (f i1 i2))) - 0 - (struct->list c1) - (struct->list c2))) + (foldl (λ (i1 i2 acc) (+ acc (f i1 i2))) 0 (struct->list c1) (struct->list c2))) (define coord-delta (curry coord-broadcast -)) (define coord-sum (curry coord-broadcast +)) @@ -23,42 +19,30 @@ (define (create-scan-data d) (for/list ([l (in-list d)]) - (for/list ([pt (in-list (~> (string-split l "\n") - rest))]) + (for/list ([pt (in-list (~> (string-split l "\n") rest))]) (~>> pt (regexp-match #px"(-?\\d+),(-?\\d+),(-?\\d+)") rest (map string->number) (apply coord))))) -(define scanner-data (create-scan-data (~>> (open-day 19 2021) - port->string - (string-split _ "\n\n")))) - -(define test-scanner-data (create-scan-data (~>> (open-input-file "test-scanners") - port->string - (string-split _ "\n\n")))) +(define scanner-data (create-scan-data (~>> (open-day 19 2021) port->string (string-split _ "\n\n")))) (define (generate-rotations scanner) - (transpose + (apply + map + list (for*/list ([pt (in-list scanner)]) (match-define (coord x y z) pt) - (define orientations (list (list x y z) - (list x z (- y)) - (list x (- y) (- z)) - (list x (- z) y))) - (append* - (for/list ([o (in-list orientations)]) - (match-define (list x* y* z*) o) - (list (list x y z) - (list (- x) z y) - (list z (- y) x) - (list y x (- z)) - (list (- y) (- z) x))))))) + (define orientations (list (list x y z) (list x z (- y)) (list x (- y) (- z)) (list x (- z) y))) + (append* (for/list ([o (in-list orientations)]) + (match-define (list x* y* z*) o) + (list (list x y z) + (list (- x) z y) + (list z (- y) x) + (list y x (- z)) + (list (- y) (- z) x))))))) (define (find-overlaps scan1 scan2) (for/list ([rotation (in-permutations scan2)]) (map coord-sum scan1 rotation))) - -(first test-scanner-data) -(find-overlaps (first test-scanner-data) (second test-scanner-data))
\ No newline at end of file |