diff options
author | J.J <thechairman@thechairman.info> | 2023-11-30 17:10:00 -0500 |
---|---|---|
committer | J.J <thechairman@thechairman.info> | 2023-11-30 17:10:00 -0500 |
commit | 8ab65dc2da1742eb86ec636c50c7018385b68167 (patch) | |
tree | c4fd556aca9b867cfa1f2f174128c30857353884 /2021/day-13 | |
parent | fafbeaf9e3c09ba7a5bea7e47d5736001f8a5aa1 (diff) | |
download | gleam_aoc-8ab65dc2da1742eb86ec636c50c7018385b68167.tar.gz gleam_aoc-8ab65dc2da1742eb86ec636c50c7018385b68167.zip |
prep for 2023, renaming for consistency
Diffstat (limited to '2021/day-13')
-rw-r--r-- | 2021/day-13/day-13.rkt | 57 |
1 files changed, 0 insertions, 57 deletions
diff --git a/2021/day-13/day-13.rkt b/2021/day-13/day-13.rkt deleted file mode 100644 index 153eabc..0000000 --- a/2021/day-13/day-13.rkt +++ /dev/null @@ -1,57 +0,0 @@ -#lang racket -(require "../../jj-aoc.rkt" - threading) - -(define (make-pt x y) - (hash 'x x 'y y)) -(struct fold (dir loc) #:transparent) -(define (make-fold dir loc) - (fold (string->symbol dir) (string->number loc))) - -(define data (port->lines (open-day 13 2021))) -(define-values (points-list folds-list) (splitf-at data (λ~> (equal? "") not))) - -(define pts - (for/set ([pt (in-list points-list)]) - (~> pt (string-split ",") (map string->number _) (apply make-pt _)))) - -(define folds - (for/list ([f (in-list (rest folds-list))]) - (~>> f (regexp-match #px"fold along (.)=(.*)") rest (apply make-fold)))) - -(define (fold-over f pts) - (define dir (fold-dir f)) - (define loc (fold-loc f)) - (for/set ([pt (in-set pts)]) - (cond - [(> (hash-ref pt dir) loc) (hash-update pt dir (λ (l) (- (* 2 loc) l)))] - [else pt]))) - -;; part 1 -(~>> pts (fold-over (first folds)) set-count) - -;; part 2 -(define final-pts - (for/fold ([pt pts]) ([f (in-list folds)]) - (fold-over f pt))) - -(define (max-dim pts dim) - (~>> (for/list ([pt (in-set pts)]) - (hash-ref pt dim)) - (apply max))) - -(for ([y (in-inclusive-range 0 (max-dim final-pts 'y))]) - (~>> (for/list ([x (in-inclusive-range 0 (max-dim final-pts 'x))]) - (if (set-member? final-pts (hash 'x x 'y y)) #\█ #\space)) - (apply string) - println)) - -#| -for this data set, the result looks like -" ██ █ █ ██ ██ ███ ██ ██ █ █" -"█ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █" -"█ █ ████ █ █ █ █ █ █ █ █ █" -"████ █ █ █ ██ █ ███ █ ██ ████ █ █" -"█ █ █ █ █ █ █ █ █ █ █ █ █ █ █" -"█ █ █ █ ███ ██ █ ███ █ █ ██ " -|# |