File tree Expand file tree Collapse file tree 2 files changed +39
-3
lines changed Expand file tree Collapse file tree 2 files changed +39
-3
lines changed Original file line number Diff line number Diff line change 11(ns advent-of-code.2017.05
2- (:require [advent-of-code.utils :as u]
3- [advent-of-code.points :as p]))
2+ (:require [advent-of-code.utils :as u]))
43
54(def path (u/get-input 2017 5 ))
6- (def tpath (u/test-path 2017 5 ))
75
86(defn run [path part2?]
97 (let [input (u/read-file-list path parse-long)
Original file line number Diff line number Diff line change 1+ (ns advent-of-code.2017.06
2+ (:require [advent-of-code.utils :as u]))
3+
4+ (def path (u/get-input 2017 6 ))
5+ (def tpath (u/test-path 2017 6 ))
6+
7+ (defn index-max [vector]
8+ (second (reduce-kv (fn [[m :as acc] idx v] (if (> v m) [v idx] acc)) [Integer/MIN_VALUE -1 ] vector)))
9+
10+ (defn run [path part1?]
11+ (let [input (u/read-file-line path u/nums)
12+ n (count input)]
13+ (loop [curr input
14+ seen (transient #{})
15+ cycles 0
16+ on? false ]
17+ (cond (and (or on? part1?) (seen curr)) cycles
18+ (seen curr) (recur curr (transient #{}) 0 true )
19+ :else (let [idx (index-max curr)
20+ v (curr idx)
21+ global (quot v n)
22+ rem (mod v n)
23+ new-c (->> (assoc curr idx 0 )
24+ (mapv #(+ global %)))]
25+ (recur (reduce (fn [acc i] (update acc (mod (+ idx i 1 ) n) inc)) new-c (range rem))
26+ (conj! seen curr)
27+ (inc cycles)
28+ on?))))))
29+
30+ (comment
31+
32+ (run tpath true )
33+ (run path true )
34+ (run tpath false )
35+ (run path false )
36+
37+ ;
38+ )
You can’t perform that action at this time.
0 commit comments