diff options
author | J.J <thechairman@thechairman.info> | 2023-11-30 17:10:00 -0500 |
---|---|---|
committer | J.J <thechairman@thechairman.info> | 2023-11-30 17:10:00 -0500 |
commit | 8ab65dc2da1742eb86ec636c50c7018385b68167 (patch) | |
tree | c4fd556aca9b867cfa1f2f174128c30857353884 /2019/day-04/day-04.rkt | |
parent | fafbeaf9e3c09ba7a5bea7e47d5736001f8a5aa1 (diff) | |
download | gleam_aoc-8ab65dc2da1742eb86ec636c50c7018385b68167.tar.gz gleam_aoc-8ab65dc2da1742eb86ec636c50c7018385b68167.zip |
prep for 2023, renaming for consistency
Diffstat (limited to '2019/day-04/day-04.rkt')
-rw-r--r-- | 2019/day-04/day-04.rkt | 39 |
1 files changed, 0 insertions, 39 deletions
diff --git a/2019/day-04/day-04.rkt b/2019/day-04/day-04.rkt deleted file mode 100644 index 9518779..0000000 --- a/2019/day-04/day-04.rkt +++ /dev/null @@ -1,39 +0,0 @@ -#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 |