-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday-23.clj
40 lines (32 loc) · 955 Bytes
/
day-23.clj
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
37
38
39
40
(ns day-23
(:require [hashp.core]))
(def parse-int #(Long/parseLong %))
(defn find-dest [current reserved]
(let [dest (dec current)]
(cond
(zero? dest) (recur 10 reserved)
(reserved dest) (recur dest reserved)
:else dest)))
(defn split-by [dest xs]
(let [[before [_ & after]]
(split-with (complement #{dest}) xs)]
[before after]))
(defn play [[current & cups]]
(let [[three others] (split-at 3 cups)
dest (find-dest current (set three))
[before after] (split-by dest others)]
(concat before (cons dest three) after (list current))))
(def rotate-while
(comp (partial apply concat) (juxt drop-while take-while)))
(defn puzzle1 [in]
(->> in
(re-seq #"\d")
(map parse-int)
(iterate play)
(take 101)
(last)
(rotate-while (complement #{1}))
(rest)
(apply str)))
(def input (->> (slurp "input23.txt")))
(time (puzzle1 input))