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/2018/01.rkt

23 lines
525 B
Racket

6 years ago
#lang debug br
(require racket/set)
(define fp (open-input-file "01.txt"))
(define frequencies
(map string->number (port->lines fp)))
(define (*)
(apply + frequencies))
(define (**)
(for/fold ([last-sum 0]
[sums (set)]
#:result last-sum)
([freq (in-cycle frequencies)]
#:break (set-member? sums last-sum))
(values (+ freq last-sum) (set-add sums last-sum))))
(module+ main
(require rackunit)
(check-equal? (time (*)) 454)
(check-equal? (time (**)) 566))