aboutsummaryrefslogtreecommitdiff
path: root/aoc2021/day-13
diff options
context:
space:
mode:
authorH.J <thechairman@thechairman.info>2024-10-09 11:36:55 -0400
committerH.J <thechairman@thechairman.info>2024-10-09 11:36:55 -0400
commit8777ff071f7bb37631baa7b6717ad29961e50911 (patch)
tree6d59c4ed58e454b960339c3d1151f0a879e8d7cb /aoc2021/day-13
parent6156a9ef7be4012063a042aafb4e9b0d7eadde8e (diff)
downloadgleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.tar.gz
gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.zip
sorting by language
Diffstat (limited to 'aoc2021/day-13')
-rw-r--r--aoc2021/day-13/day-13.rkt57
1 files changed, 0 insertions, 57 deletions
diff --git a/aoc2021/day-13/day-13.rkt b/aoc2021/day-13/day-13.rkt
deleted file mode 100644
index 153eabc..0000000
--- a/aoc2021/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
-" ██ █ █ ██ ██ ███ ██ ██ █ █"
-"█ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █"
-"█ █ ████ █ █ █ █ █ █ █ █ █"
-"████ █ █ █ ██ █ ███ █ ██ ████ █ █"
-"█ █ █ █ █ █ █ █ █ █ █ █ █ █ █"
-"█ █ █ █ ███ ██ █ ███ █ █ ██ "
-|#