diff options
author | HJ <thechairman@thechairman.info> | 2023-12-18 08:52:09 -0500 |
---|---|---|
committer | HJ <thechairman@thechairman.info> | 2023-12-18 08:52:09 -0500 |
commit | 662dc6d30da9325590a59eb506880d1d2e5ecfb2 (patch) | |
tree | 4532ca723492331d409b432fa37a2bd8daa5443c /aoc2023-other | |
parent | ee8001fe861ddb62b042a5904cfb57b5c511d2e7 (diff) | |
download | gleam_aoc-662dc6d30da9325590a59eb506880d1d2e5ecfb2.tar.gz gleam_aoc-662dc6d30da9325590a59eb506880d1d2e5ecfb2.zip |
day 18 racket revised
Diffstat (limited to 'aoc2023-other')
-rw-r--r-- | aoc2023-other/day-18/day-18.rkt | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/aoc2023-other/day-18/day-18.rkt b/aoc2023-other/day-18/day-18.rkt index 4d3e95b..c18a750 100644 --- a/aoc2023-other/day-18/day-18.rkt +++ b/aoc2023-other/day-18/day-18.rkt @@ -9,10 +9,10 @@ (define (go-to-next-coord c dir dist) (match-define (coord x y) c) (match dir - ["R" (coord (+ x dist) y)] - ["L" (coord (- x dist) y)] - ["U" (coord x (+ y dist))] - ["D" (coord x (- y dist))])) + [(or "R" "0") (coord (+ x dist) y)] + [(or "D" "1") (coord x (- y dist))] + [(or "L" "2") (coord (- x dist) y)] + [(or "U" "3") (coord x (+ y dist))])) (define/match (triangle-area _coord1 _coord2) [((coord x1 y1) (coord x2 y2)) (/ (- (* x1 y2) (* x2 y1)) 2)]) @@ -37,15 +37,8 @@ ;; part 2 (define (parse-hex dig) - (match-define (regexp #rx".*\\(#(.....)(.)\\)" - (list _ (app (curryr string->number 16) dist) (app num->dir dir))) + (match-define (regexp #rx".*\\(#(.....)(.)\\)" (list _ (app (curryr string->number 16) dist) dir)) dig) (values dir dist)) -(define/match (num->dir _n) - [("0") "R"] - [("1") "D"] - [("2") "L"] - [("3") "U"]) - (find-area-using parse-hex) |