-
Notifications
You must be signed in to change notification settings - Fork 0
/
day5.rkt
26 lines (20 loc) · 812 Bytes
/
day5.rkt
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
#lang racket
(define instructions (map string->number (file->lines "day5-input.txt")))
(define (walk1 instructions pos acc)
(if (or (>= pos (length instructions)) (< pos 0))
(println acc)
(let ([jump (list-ref instructions pos)])
(walk1 (list-set instructions pos (+ jump 1)) (+ pos jump) (+ acc 1)))))
(define (walk2 instructions pos acc)
(if (or (>= pos (length instructions)) (< pos 0))
(println acc)
(let ([jump (list-ref instructions pos)])
(walk2 (list-set instructions pos
(if (>= jump 3)
(- jump 1)
(+ jump 1))
)
(+ pos jump)
(+ acc 1)))))
(walk1 instructions 0 0)
(walk2 instructions 0 0)