aboutsummaryrefslogtreecommitdiff
path: root/2015
diff options
context:
space:
mode:
authorHunky Jimpjorps <thechairman@thechairman.info>2022-11-26 01:43:33 -0500
committerHunky Jimpjorps <thechairman@thechairman.info>2022-11-26 01:43:33 -0500
commitfeccf3f6f0a806b3317d1f399e3e8b42945c4f09 (patch)
treebf15ce045d1106c1b7f7de30c27540f40d0bf947 /2015
parent8b624fe7d2751337b1f16830cc9c041df73e99e7 (diff)
downloadgleam_aoc-feccf3f6f0a806b3317d1f399e3e8b42945c4f09.tar.gz
gleam_aoc-feccf3f6f0a806b3317d1f399e3e8b42945c4f09.zip
using raco fmt, replacing missing dependency
Diffstat (limited to '2015')
-rw-r--r--2015/day-01/day-01.rkt13
-rw-r--r--2015/day-02/day-02.rkt34
-rw-r--r--2015/day-03/day-03.rkt14
-rw-r--r--2015/day-04/day-04.rkt13
-rw-r--r--2015/day-05/day-05.rkt19
-rw-r--r--2015/day-06/day-06.rkt9
-rw-r--r--2015/day-25/day-25.rkt14
7 files changed, 29 insertions, 87 deletions
diff --git a/2015/day-01/day-01.rkt b/2015/day-01/day-01.rkt
index 2432c96..efbd02a 100644
--- a/2015/day-01/day-01.rkt
+++ b/2015/day-01/day-01.rkt
@@ -2,20 +2,15 @@
(require "../../jj-aoc.rkt")
;; part 1
-(for/fold ([current-floor 0])
- ([l (in-input-port-chars (open-day 1 2015))]
- [i (in-naturals)])
+(for/fold ([current-floor 0]) ([l (in-input-port-chars (open-day 1 2015))] [i (in-naturals)])
(match l
[#\( (add1 current-floor)]
[#\) (sub1 current-floor)]))
;; part 2
-(for/fold ([current-floor 0]
- [last-index 0]
- #:result (add1 last-index))
- ([l (in-input-port-chars (open-day 1 2015))]
- [i (in-naturals)])
+(for/fold ([current-floor 0] [last-index 0] #:result (add1 last-index))
+ ([l (in-input-port-chars (open-day 1 2015))] [i (in-naturals)])
#:break (= current-floor -1)
(match l
[#\( (values (add1 current-floor) i)]
- [#\) (values (sub1 current-floor) i)])) \ No newline at end of file
+ [#\) (values (sub1 current-floor) i)]))
diff --git a/2015/day-02/day-02.rkt b/2015/day-02/day-02.rkt
index 870e380..579fd00 100644
--- a/2015/day-02/day-02.rkt
+++ b/2015/day-02/day-02.rkt
@@ -7,42 +7,20 @@
(define presents
(for/list ([size-string (in-lines (open-day 2 2015))])
- (~> size-string
- (string-split "x")
- (map string->number _)
- (apply present _))))
+ (~> size-string (string-split "x") (map string->number _) (apply present _))))
;; part 1
(define (paper-area p)
- (define main-area
- (~> p
- struct->list
- (combinations 2)
- (map (λ~> (apply * 2 _)) _)
- (apply + _)))
- (define slack-area
- (~> p
- struct->list
- (sort <)
- (take 2)
- (apply * _)))
+ (define main-area (~> p struct->list (combinations 2) (map (λ~> (apply * 2 _)) _) (apply + _)))
+ (define slack-area (~> p struct->list (sort <) (take 2) (apply * _)))
(+ main-area slack-area))
(for/sum ([p (in-list presents)]) (paper-area p))
;; part 2
(define (ribbon-length p)
- (define ribbon-around-box
- (~> p
- struct->list
- (sort <)
- (take 2)
- (map (λ~> (* 2)) _)
- (apply + _)))
- (define ribbon-for-bow
- (~> p
- struct->list
- (apply * _)))
+ (define ribbon-around-box (~> p struct->list (sort <) (take 2) (map (λ~> (* 2)) _) (apply + _)))
+ (define ribbon-for-bow (~> p struct->list (apply * _)))
(+ ribbon-around-box ribbon-for-bow))
-(for/sum ([p (in-list presents)]) (ribbon-length p)) \ No newline at end of file
+(for/sum ([p (in-list presents)]) (ribbon-length p))
diff --git a/2015/day-03/day-03.rkt b/2015/day-03/day-03.rkt
index efa09ad..1d44955 100644
--- a/2015/day-03/day-03.rkt
+++ b/2015/day-03/day-03.rkt
@@ -2,7 +2,6 @@
(require "../../jj-aoc.rkt"
threading
(only-in algorithms chunks-of)
- (only-in awesome-list transpose)
racket/hash)
(define directions
@@ -11,10 +10,7 @@
(define (trace-santa dirs)
(define visits (make-hash))
- (for/fold ([x 0]
- [y 0]
- #:result visits)
- ([dir (in-list dirs)])
+ (for/fold ([x 0] [y 0] #:result visits) ([dir (in-list dirs)])
(hash-set! visits `(,x ,y) #true)
(match dir
['^ (values x (add1 y))]
@@ -26,11 +22,7 @@
(~> directions trace-santa hash-values length)
;; part 2
-(~> directions
- (chunks-of 2)
- transpose
- (map trace-santa _)
- (match-define (list real robo) _))
+(~> directions (chunks-of 2) (apply map list _) (map trace-santa _) (match-define (list real robo) _))
(hash-union! real robo #:combine (λ _ #true))
-(~> real hash-values length) \ No newline at end of file
+(~> real hash-values length)
diff --git a/2015/day-04/day-04.rkt b/2015/day-04/day-04.rkt
index 4008b92..2c16043 100644
--- a/2015/day-04/day-04.rkt
+++ b/2015/day-04/day-04.rkt
@@ -3,21 +3,16 @@
threading
file/md5)
-(define secret-key (~> (open-day 4 2015)
- port->string
- string-trim))
+(define secret-key (~> (open-day 4 2015) port->string string-trim))
(define (find-n-zeroes n)
(for/first ([i (in-naturals)]
- #:when (~>> i
- (~a secret-key)
- md5
- bytes->string/utf-8
- (string-prefix? _ (make-string n #\0))))
+ #:when
+ (~>> i (~a secret-key) md5 bytes->string/utf-8 (string-prefix? _ (make-string n #\0))))
i))
;; part 1
(time (find-n-zeroes 5))
;; part 2
-(time (find-n-zeroes 6)) \ No newline at end of file
+(time (find-n-zeroes 6))
diff --git a/2015/day-05/day-05.rkt b/2015/day-05/day-05.rkt
index 9714a0f..3449adc 100644
--- a/2015/day-05/day-05.rkt
+++ b/2015/day-05/day-05.rkt
@@ -6,24 +6,16 @@
;; part 1
(define (at-least-three-vowels? str)
- (~>> str
- (regexp-replace* #px"[^aeiou]" _ "")
- string-length
- (<= 3)))
+ (~>> str (regexp-replace* #px"[^aeiou]" _ "") string-length (<= 3)))
(define (at-least-one-pair? str)
(regexp-match? #px"(.)\\1{1,}" str))
(define (no-forbidden-pairs? str)
- (~>> (list "ab" "cd" "pq" "xy")
- (ormap (λ~>> (string-contains? str)))
- not))
+ (~>> (list "ab" "cd" "pq" "xy") (ormap (λ~>> (string-contains? str))) not))
(define (nice? str)
- (~>> (list at-least-three-vowels?
- at-least-one-pair?
- no-forbidden-pairs?)
- (andmap (λ (f) (f str)))))
+ (~>> (list at-least-three-vowels? at-least-one-pair? no-forbidden-pairs?) (andmap (λ (f) (f str)))))
(count nice? strs)
@@ -35,7 +27,6 @@
(regexp-match? #px"(.).\\1" str))
(define (new-nice? str)
- (~>> (list repeating-pair? symmetry?)
- (andmap (λ (f) (f str)))))
+ (~>> (list repeating-pair? symmetry?) (andmap (λ (f) (f str)))))
-(count new-nice? strs) \ No newline at end of file
+(count new-nice? strs)
diff --git a/2015/day-06/day-06.rkt b/2015/day-06/day-06.rkt
index 2cafa4e..d2eed08 100644
--- a/2015/day-06/day-06.rkt
+++ b/2015/day-06/day-06.rkt
@@ -10,7 +10,8 @@
(define instructions
(for/list ([l (in-lines (open-day 6 2015))])
(~>> l
- (regexp-match #px"(turn on|toggle|turn off) (\\d{1,3}),(\\d{1,3}) through (\\d{1,3}),(\\d{1,3})")
+ (regexp-match
+ #px"(turn on|toggle|turn off) (\\d{1,3}),(\\d{1,3}) through (\\d{1,3}),(\\d{1,3})")
rest
make-instruction)))
@@ -30,8 +31,7 @@
(for ([y (inclusive-range (instruction-y1 inst) (instruction-y2 inst))])
(vector2d-modify! light-grid x y (using inst)))))
-(define light-grid
- (make-vector (* 1000 1000) #false))
+(define light-grid (make-vector (* 1000 1000) #false))
(for ([i (in-list instructions)])
(modify-light-grid i light-grid todo))
(vector-count identity light-grid)
@@ -43,8 +43,7 @@
['|turn off| (λ (x) (max 0 (sub1 x)))]
['|toggle| (curry + 2)]))
-(define dimmable-grid
- (make-vector (* 1000 1000) 0))
+(define dimmable-grid (make-vector (* 1000 1000) 0))
(for ([i (in-list instructions)])
(modify-light-grid i dimmable-grid todo-dimmer))
(apply + (vector->list dimmable-grid))
diff --git a/2015/day-25/day-25.rkt b/2015/day-25/day-25.rkt
index 786538c..975f4c3 100644
--- a/2015/day-25/day-25.rkt
+++ b/2015/day-25/day-25.rkt
@@ -3,14 +3,6 @@
(define max-r 2978)
(define max-c 3083)
-(for/fold ([code 20151125]
- [r 1]
- [c 1])
- ([i (in-naturals)]
- #:break (and (= max-r r)
- (= max-c c)))
- (define new-code
- (modulo (* code 252533) 33554393))
- (if (= r 1)
- (values new-code (add1 c) 1)
- (values new-code (sub1 r) (add1 c))))
+(for/fold ([code 20151125] [r 1] [c 1]) ([i (in-naturals)] #:break (and (= max-r r) (= max-c c)))
+ (define new-code (modulo (* code 252533) 33554393))
+ (if (= r 1) (values new-code (add1 c) 1) (values new-code (sub1 r) (add1 c))))