aboutsummaryrefslogtreecommitdiff
path: root/2020/day-04
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/day-04
parent8b624fe7d2751337b1f16830cc9c041df73e99e7 (diff)
downloadgleam_aoc-feccf3f6f0a806b3317d1f399e3e8b42945c4f09.tar.gz
gleam_aoc-feccf3f6f0a806b3317d1f399e3e8b42945c4f09.zip
using raco fmt, replacing missing dependency
Diffstat (limited to '2020/day-04')
-rw-r--r--2020/day-04/day-04.rkt32
1 files changed, 7 insertions, 25 deletions
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)))