aboutsummaryrefslogtreecommitdiff
path: root/2020/day-04
diff options
context:
space:
mode:
authorHJ <thechairman@thechairman.info>2021-12-11 21:51:00 -0500
committerHJ <thechairman@thechairman.info>2021-12-11 21:51:00 -0500
commitf8281d7bb70bd412c961a2ca6ea675d3231af54d (patch)
treec34b7de9d7b234704198fc345bc16f9eb5608a34 /2020/day-04
parent0acfa0750900ece33b1e5aaef492db2a33fa60d7 (diff)
parent1855292990b1d423aae36bcf501bc20ddcf6ae82 (diff)
downloadgleam_aoc-f8281d7bb70bd412c961a2ca6ea675d3231af54d.tar.gz
gleam_aoc-f8281d7bb70bd412c961a2ca6ea675d3231af54d.zip
Merge branch 'main' of https://github.com/hunkyjimpjorps/AdventOfCode
Diffstat (limited to '2020/day-04')
-rw-r--r--2020/day-04/day-04.rkt49
1 files changed, 49 insertions, 0 deletions
diff --git a/2020/day-04/day-04.rkt b/2020/day-04/day-04.rkt
new file mode 100644
index 0000000..3c7db89
--- /dev/null
+++ b/2020/day-04/day-04.rkt
@@ -0,0 +1,49 @@
+#lang racket
+(require "../../jj-aoc.rkt"
+ threading)
+
+(define passports
+ (~> (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 (valid-passport? p)
+ (andmap (λ (s) (string-contains? p s)) required-fields))
+
+(count valid-passport? passports)
+
+;; 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 _))))
+
+(define (valid-byr p)
+ (define year (string->number (hash-ref p "byr")))
+ (and (<= year 1920)
+ (>= year 2002)))
+
+(define (valid-iyr p)
+ (define year (string->number (hash-ref p "iyr")))
+ (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