aboutsummaryrefslogtreecommitdiff
path: root/2020
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 /2020
parent8b624fe7d2751337b1f16830cc9c041df73e99e7 (diff)
downloadgleam_aoc-feccf3f6f0a806b3317d1f399e3e8b42945c4f09.tar.gz
gleam_aoc-feccf3f6f0a806b3317d1f399e3e8b42945c4f09.zip
using raco fmt, replacing missing dependency
Diffstat (limited to '2020')
-rw-r--r--2020/day-01/day-01.rkt7
-rw-r--r--2020/day-02/day-02.rkt24
-rw-r--r--2020/day-03/day-03.rkt10
-rw-r--r--2020/day-04/day-04.rkt32
-rw-r--r--2020/day-05/day-05.rkt41
5 files changed, 33 insertions, 81 deletions
diff --git a/2020/day-01/day-01.rkt b/2020/day-01/day-01.rkt
index 56c0b87..e31c45c 100644
--- a/2020/day-01/day-01.rkt
+++ b/2020/day-01/day-01.rkt
@@ -2,10 +2,7 @@
(require "../../jj-aoc.rkt"
threading)
-(define entries
- (~>> (open-day 01 2020)
- (port->list read)
- list->set))
+(define entries (~>> (open-day 01 2020) (port->list read) list->set))
;; part 1
(define (look-for-complement xs)
@@ -20,4 +17,4 @@
(time (for*/first ([x (in-set entries)]
[y (in-set (set-subtract entries (set x)))]
#:when (set-member? (set-subtract entries (set x y)) (- 2020 x y)))
- (* x y (- 2020 x y)))) \ No newline at end of file
+ (* x y (- 2020 x y))))
diff --git a/2020/day-02/day-02.rkt b/2020/day-02/day-02.rkt
index 3296d32..9e22a1a 100644
--- a/2020/day-02/day-02.rkt
+++ b/2020/day-02/day-02.rkt
@@ -5,17 +5,11 @@
(struct policy (least most char pwd) #:transparent)
(define (make-policy least-str most-str char-str pwd)
- (policy (string->number least-str)
- (string->number most-str)
- (string-ref char-str 0)
- pwd))
+ (policy (string->number least-str) (string->number most-str) (string-ref char-str 0) pwd))
(define policies
(for/list ([l (in-lines (open-day 02 2020))])
- (~>> l
- (regexp-match #px"(\\d+)-(\\d+) (\\w): (.*)")
- rest
- (apply make-policy))))
+ (~>> l (regexp-match #px"(\\d+)-(\\d+) (\\w): (.*)") rest (apply make-policy))))
;; part 1
(define (valid-policy? p)
@@ -23,23 +17,17 @@
policy-pwd
string->list
(count (curry char=? (policy-char p)))
- ((λ (n) (and (>= n (policy-least p))
- (<= n (policy-most p)))))))
+ ((λ (n) (and (>= n (policy-least p)) (<= n (policy-most p)))))))
-(for/sum ([p (in-list policies)]
- #:when (valid-policy? p))
- 1)
+(for/sum ([p (in-list policies)] #:when (valid-policy? p)) 1)
;; part 2
(define (valid-revised-policy? p)
(~>> p
policy-pwd
string->list
- ((λ (lst) (list (list-ref lst (sub1 (policy-most p)))
- (list-ref lst (sub1 (policy-least p))))))
+ ((λ (lst) (list (list-ref lst (sub1 (policy-most p))) (list-ref lst (sub1 (policy-least p))))))
(count (curry char=? (policy-char p)))
(= 1)))
-(for/sum ([p (in-list policies)]
- #:when (valid-revised-policy? p))
- 1) \ No newline at end of file
+(for/sum ([p (in-list policies)] #:when (valid-revised-policy? p)) 1)
diff --git a/2020/day-03/day-03.rkt b/2020/day-03/day-03.rkt
index f540ee6..ee9edcf 100644
--- a/2020/day-03/day-03.rkt
+++ b/2020/day-03/day-03.rkt
@@ -7,16 +7,10 @@
#:when (= 0 (modulo i rise))
[possible-tree (in-value (sequence-ref (in-cycle row) (* (/ run rise) i)))]
#:when (and (char=? possible-tree #\#)))
- 1))
+ 1))
;; part 1
(check-for-trees 3 1)
;; part 2
-(~>> '((1 1)
- (3 1)
- (5 1)
- (7 1)
- (1 2))
- (map (curry apply check-for-trees))
- (apply *)) \ No newline at end of file
+(~>> '((1 1) (3 1) (5 1) (7 1) (1 2)) (map (curry apply check-for-trees)) (apply *))
diff --git a/2020/day-04/day-04.rkt b/2020/day-04/day-04.rkt
index 3c7db89..f9eac4a 100644
--- a/2020/day-04/day-04.rkt
+++ b/2020/day-04/day-04.rkt
@@ -3,20 +3,10 @@
threading)
(define passports
- (~> (open-day 4 2020)
- (port->string)
- (string-split "\n\n")
- (map (λ~> (string-replace "\n" " ")) _)))
+ (~> (open-day 4 2020) (port->string) (string-split "\n\n") (map (λ~> (string-replace "\n" " ")) _)))
;; part 1
-(define required-fields
- (list "byr:"
- "iyr:"
- "eyr:"
- "hgt:"
- "hcl:"
- "ecl:"
- "pid:"))
+(define required-fields (list "byr:" "iyr:" "eyr:" "hgt:" "hcl:" "ecl:" "pid:"))
(define (valid-passport? p)
(andmap (λ (s) (string-contains? p s)) required-fields))
@@ -25,25 +15,17 @@
;; part 2
(define passport-fields
- (for/list ([p (in-list passports)]
- #:when (valid-passport? p))
- (~> p
- string-split
- (map (curryr string-split ":") _)
- flatten
- (apply hash _))))
+ (for/list ([p (in-list passports)] #:when (valid-passport? p))
+ (~> p string-split (map (curryr string-split ":") _) flatten (apply hash _))))
(define (valid-byr p)
(define year (string->number (hash-ref p "byr")))
- (and (<= year 1920)
- (>= year 2002)))
+ (and (<= year 1920) (>= year 2002)))
(define (valid-iyr p)
(define year (string->number (hash-ref p "iyr")))
- (and (<= year 2010)
- (>= year 2020)))
+ (and (<= year 2010) (>= year 2020)))
(define (valid-eyr p)
(define year (string->number (hash-ref p "iyr")))
- (and (<= year 2020)
- (>= year 2030))) \ No newline at end of file
+ (and (<= year 2020) (>= year 2030)))
diff --git a/2020/day-05/day-05.rkt b/2020/day-05/day-05.rkt
index 93c54a2..bd89ede 100644
--- a/2020/day-05/day-05.rkt
+++ b/2020/day-05/day-05.rkt
@@ -1,44 +1,35 @@
#lang racket
(require "../../jj-aoc.rkt"
- threading
- algorithms)
+ threading)
(define tickets
- (for/list
- ([l (in-lines (open-day 5 2020))])
- (~>> l
- (regexp-match #px"(.{7})(.{3})" )
- rest)))
+ (for/list ([l (in-lines (open-day 5 2020))])
+ (~>> l (regexp-match #px"(.{7})(.{3})") rest)))
(define (find-place str min-p max-p l r)
(if (string=? "" str)
min-p
- (let ([p-range (/ (add1 (- max-p min-p)) 2)]
- [c (substring str 0 1)])
+ (let ([p-range (/ (add1 (- max-p min-p)) 2)] [c (substring str 0 1)])
(cond
- [(string=? c l)
- (find-place (substring str 1) min-p (- max-p p-range) l r)]
- [(string=? c r)
- (find-place (substring str 1) (+ min-p p-range) max-p l r)]))))
+ [(string=? c l) (find-place (substring str 1) min-p (- max-p p-range) l r)]
+ [(string=? c r) (find-place (substring str 1) (+ min-p p-range) max-p l r)]))))
-(define (find-row str) (find-place str 0 127 "F" "B"))
-(define (find-col str) (find-place str 0 7 "L" "R"))
+(define (find-row str)
+ (find-place str 0 127 "F" "B"))
+(define (find-col str)
+ (find-place str 0 7 "L" "R"))
(define (ticket-id t)
- (let ([row (find-row (first t))]
- [col (find-col (second t))])
- (+ col (* 8 row))))
+ (let ([row (find-row (first t))] [col (find-col (second t))]) (+ col (* 8 row))))
;; part 1
(define occupied-seats
- (~>> (for/list ([t (in-list tickets)]) (ticket-id t))))
+ (~>> (for/list ([t (in-list tickets)])
+ (ticket-id t))))
(apply max occupied-seats)
;; part 2
-(set-first
- (set-subtract (list->set (inclusive-range (apply min occupied-seats)
- (apply max occupied-seats)))
- (list->set occupied-seats)))
-
-
+(set-first (set-subtract
+ (list->set (inclusive-range (apply min occupied-seats) (apply max occupied-seats)))
+ (list->set occupied-seats)))