aboutsummaryrefslogtreecommitdiff
path: root/2020/day-04/day-04.rkt
diff options
context:
space:
mode:
Diffstat (limited to '2020/day-04/day-04.rkt')
-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)))