Overview
Comment: | Day 1 solutions (both parts) |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
6b74a14c4253754be4e2923c00e54cb0 |
User & Date: | joel on 2018-12-01 23:16:30 |
Other Links: | manifest | tags |
Context
2018-12-02
| ||
17:26 | Add Day 2 input and solutions check-in: 35dfec user: joel tags: trunk | |
2018-12-01
| ||
23:16 | Day 1 solutions (both parts) check-in: 6b74a1 user: joel tags: trunk | |
21:18 | Add Readme file check-in: 1c0a94 user: joel tags: trunk | |
Changes
Added day01.rkt version [433e28].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 32 33 34 35 36 | #lang racket (require rackunit) (define input (file->lines "day01-input.txt")) (define start-frequency 0) (define (day01-part1) (apply + start-frequency (map string->number input))) (module+ test (check-equal? (day01-part1) 486)) ; Correct answer for part1 (define (day01-part2 [freq-changes (map string->number input)] [start-from start-frequency] [seen-frequencies (list start-frequency)]) (define run-through (for/fold ([seen seen-frequencies] [current-freq start-from] #:result seen) ([freq-change (in-list freq-changes)]) #:final (member (+ current-freq freq-change) seen) (values (append seen (list (+ current-freq freq-change))) (+ current-freq freq-change)))) (cond [(check-duplicates run-through) (last run-through)] [else (day01-part2 freq-changes (last run-through) run-through)])) (module+ test (check-equal? (day01-part2 '(3 3 4 -2 -4)) 10) (check-equal? (day01-part2 '(-6 3 8 5 -6)) 5) (check-equal? (day01-part2 '(7 7 -2 -7 -4)) 14) ; Actually getting the correct answer for my input takes a really long time ; (check-equal? (day01-part2) 69285) ) |