aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHunky Jimpjorps <thechairman@thechairman.info>2022-12-25 16:50:52 -0500
committerHunky Jimpjorps <thechairman@thechairman.info>2022-12-25 16:50:52 -0500
commitb5d346027963eddd9613e3aa9ad11be2c06e40e8 (patch)
tree2e77d1735f1a62e4a6a55b0c97e261196415bd1e
parentfd94f5238073368d96d9af28070402411c2ad28f (diff)
downloadgleam_aoc-b5d346027963eddd9613e3aa9ad11be2c06e40e8.tar.gz
gleam_aoc-b5d346027963eddd9613e3aa9ad11be2c06e40e8.zip
2019 day 4 complete
-rw-r--r--2019/day-04/day-04.rkt39
-rw-r--r--2019/day-05/day-05.rkt1
2 files changed, 40 insertions, 0 deletions
diff --git a/2019/day-04/day-04.rkt b/2019/day-04/day-04.rkt
new file mode 100644
index 0000000..9518779
--- /dev/null
+++ b/2019/day-04/day-04.rkt
@@ -0,0 +1,39 @@
+#lang racket
+
+(define (number->digits n [acc '()])
+ (cond
+ [(< n 10) (cons n acc)]
+ [else (number->digits (quotient n 10) (cons (remainder n 10) acc))]))
+
+(define (always-increasing? xs)
+ (match xs
+ [(list _) #t]
+ [(list* a b _) #:when (<= a b) (always-increasing? (cdr xs))]
+ [_ #f]))
+
+(define (adjacent-pair? xs)
+ (match xs
+ [(list _) #f]
+ [(list* a a _) a]
+ [_ (adjacent-pair? (cdr xs))]))
+
+;; part 1
+(for/sum ([password (inclusive-range 125730 579381)]
+ #:do [(define digits (number->digits password))]
+ #:when ((conjoin always-increasing? adjacent-pair?) digits))
+ 1)
+
+;; part 2
+(define (not-in-adjacent-triplet? xs)
+ (match xs
+ [(list a a c _ _ _) #:when (not (= a c)) #t]
+ [(list b a a c _ _) #:when (not (or (= a b) (= a c))) #t]
+ [(list _ b a a c _) #:when (not (or (= a b) (= a c))) #t]
+ [(list _ _ b a a c) #:when (not (or (= a b) (= a c))) #t]
+ [(list _ _ _ b a a) #:when (not (= a b)) #t]
+ [_ #f]))
+
+(for/sum ([password (inclusive-range 125730 579381)]
+ #:do [(define digits (number->digits password))]
+ #:when ((conjoin always-increasing? adjacent-pair? not-in-adjacent-triplet?) digits))
+ 1) \ No newline at end of file
diff --git a/2019/day-05/day-05.rkt b/2019/day-05/day-05.rkt
new file mode 100644
index 0000000..6f1f7b4
--- /dev/null
+++ b/2019/day-05/day-05.rkt
@@ -0,0 +1 @@
+#lang racket