diff options
author | Leah Neukirchen <leah@vuxu.org> | 2022-12-05 17:09:30 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2022-12-05 17:09:30 +0100 |
commit | 68ee54cfaa49f438bb7ad93e7c595e72c64dfbbd (patch) | |
tree | 69851f9e3e59944d64a1e25db212f1082b852878 /day04.rkt | |
parent | fe9b273cc83c4b6448c0e78c76b6dd2060522f14 (diff) | |
download | adventofcode2022-68ee54cfaa49f438bb7ad93e7c595e72c64dfbbd.tar.gz adventofcode2022-68ee54cfaa49f438bb7ad93e7c595e72c64dfbbd.tar.xz adventofcode2022-68ee54cfaa49f438bb7ad93e7c595e72c64dfbbd.zip |
day04
Diffstat (limited to 'day04.rkt')
-rw-r--r-- | day04.rkt | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/day04.rkt b/day04.rkt new file mode 100644 index 0000000..4f9ba21 --- /dev/null +++ b/day04.rkt @@ -0,0 +1,31 @@ +#lang racket +(require (for-syntax syntax/for-body) + syntax/parse/define) + +(define-syntax-parse-rule (for/count clauses body ... tail-expr) + #:with original this-syntax + #:with ((pre-body ...) (post-body ...)) + (split-for-body this-syntax #'(body ... tail-expr)) + (for/fold/derived original + ([count 0]) + clauses + pre-body ... + (define maybe-count (let () post-body ...)) + (if maybe-count + (+ count 1) + count))) + + +(for/count ([line (file->lines "day04")]) + (match-let ([(list a b c d) (map string->number + (string-split line #px"[^0-9]"))]) + (or (<= a c d b) + (<= c a b d)))) +; 651 + +(for/count ([line (file->lines "day04")]) + (match-let ([(list a b c d) (map string->number + (string-split line #px"[^0-9]"))]) + (and (<= c b) + (<= a d)))) +; 956 |