Browse Source

the tortoise and the pain

master
Hazel Levine 1 year ago
parent
commit
52bc2add55
Signed by: hazel
GPG Key ID: 1884029A28789A62
  1. 2000
      data/day1.txt
  2. 22
      day1.rkt

2000
data/day1.txt

File diff suppressed because it is too large Load Diff

22
day1.rkt

@ -1,15 +1,31 @@
#lang racket
(require "lib/common.rkt")
(define (sum lst) (foldr + 0 lst))
(define (day1a lst)
(void))
(for/sum ([v (in-list lst)]
[next (in-list (rest lst))])
(if (< v next) 1 0)))
(define (day1b lst)
(void))
(define sum-list
(let loop ([current-lst lst])
(cond [(< (length current-lst) 3) empty]
[else (cons (sum (take current-lst 3))
(loop (rest current-lst)))])))
(day1a sum-list))
(module+ main
(call-with-input-file "data/day1.txt"
(lambda (prt)
(define lines (port->lines prt))
(define lines (map string->number (port->lines prt)))
(answer 1 1 (day1a lines))
(answer 1 2 (day1b lines)))))
(module+ test
(require rackunit)
(define lines '(199 200 208 210 200 207 240 269 260 263))
(check-equal? (day1b lines) 5))

Loading…
Cancel
Save