blob: 4f9ba2123b1f7b61f77c691624094d8fa802c082 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
|