diff options
author | H.J <thechairman@thechairman.info> | 2024-10-09 11:36:55 -0400 |
---|---|---|
committer | H.J <thechairman@thechairman.info> | 2024-10-09 11:36:55 -0400 |
commit | 8777ff071f7bb37631baa7b6717ad29961e50911 (patch) | |
tree | 6d59c4ed58e454b960339c3d1151f0a879e8d7cb /aoc2020/day-02/day-02.rkt | |
parent | 6156a9ef7be4012063a042aafb4e9b0d7eadde8e (diff) | |
download | gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.tar.gz gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.zip |
sorting by language
Diffstat (limited to 'aoc2020/day-02/day-02.rkt')
-rw-r--r-- | aoc2020/day-02/day-02.rkt | 33 |
1 files changed, 0 insertions, 33 deletions
diff --git a/aoc2020/day-02/day-02.rkt b/aoc2020/day-02/day-02.rkt deleted file mode 100644 index 9e22a1a..0000000 --- a/aoc2020/day-02/day-02.rkt +++ /dev/null @@ -1,33 +0,0 @@ -#lang racket -(require "../../jj-aoc.rkt" - threading) - -(struct policy (least most char pwd) #:transparent) - -(define (make-policy least-str most-str char-str pwd) - (policy (string->number least-str) (string->number most-str) (string-ref char-str 0) pwd)) - -(define policies - (for/list ([l (in-lines (open-day 02 2020))]) - (~>> l (regexp-match #px"(\\d+)-(\\d+) (\\w): (.*)") rest (apply make-policy)))) - -;; part 1 -(define (valid-policy? p) - (~>> p - policy-pwd - string->list - (count (curry char=? (policy-char p))) - ((λ (n) (and (>= n (policy-least p)) (<= n (policy-most p))))))) - -(for/sum ([p (in-list policies)] #:when (valid-policy? p)) 1) - -;; part 2 -(define (valid-revised-policy? p) - (~>> p - policy-pwd - string->list - ((λ (lst) (list (list-ref lst (sub1 (policy-most p))) (list-ref lst (sub1 (policy-least p)))))) - (count (curry char=? (policy-char p))) - (= 1))) - -(for/sum ([p (in-list policies)] #:when (valid-revised-policy? p)) 1) |