You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
aoc-racket/2020/03.rkt

20 lines
687 B
Racket

#lang br
(require racket/file rackunit)
(define (trees-in-slope horiz vert)
(for/fold ([mod 0]
[sum 0]
#:result sum)
([(ln lidx) (in-indexed (file->lines "03.rktd"))]
#:when (zero? (modulo lidx vert)))
(values (+ mod horiz)
(if (char=? #\# (string-ref ln (modulo mod (string-length ln)))) (add1 sum) sum))))
(check-equal? (trees-in-slope 3 1) 151)
(check-equal? (apply * (list
(trees-in-slope 1 1)
(trees-in-slope 3 1)
(trees-in-slope 5 1)
(trees-in-slope 7 1)
(trees-in-slope 1 2))) 7540141059)