-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday5.carp
34 lines (30 loc) · 845 Bytes
/
day5.carp
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
; https://github.com/eriksvedang/advent_of_code_2017/blob/master/eriksvedang-carp/day5.carp
(use Int)
(use Array)
(use IO)
(defn answer [ints f]
(let [pos 0
len (count &ints)
steps 0]
(do
(while (and (< -1 pos) (< pos len))
(let [jump @(nth &ints pos)]
(do
(aset! &ints pos (f jump)) ;; modify instruction
(set! &pos (+ pos jump)) ;; jump!
(set! &steps (inc steps)))))
steps)))
(defn part-2 [x]
(if (< x 3)
(+ x 1)
(- x 1)))
(defn main []
(let [input (read-file "../../resources/2017/day5")
ints (copy-map from-string &(lines input))]
(do
(println (refstr (answer @&ints inc)))
(println (refstr (answer @&ints part-2))))))
;$ carp
;> (load "day5.carp")
;> (build)
;> (run)