do 2017 day 10
This commit is contained in:
@@ -0,0 +1,56 @@
|
|||||||
|
(ns day10
|
||||||
|
(:require
|
||||||
|
[clojure.string :as str]
|
||||||
|
[input-manager]))
|
||||||
|
|
||||||
|
(def input (input-manager/get-input-raw 2017 10))
|
||||||
|
|
||||||
|
(defn pinch-and-rotate [data pos length]
|
||||||
|
(->> data
|
||||||
|
cycle
|
||||||
|
(drop pos)
|
||||||
|
(take length)
|
||||||
|
reverse
|
||||||
|
(map-indexed vector)
|
||||||
|
(reduce (fn [acc [idx el]]
|
||||||
|
(assoc acc (mod (+ pos idx) (count data)) el))
|
||||||
|
data)))
|
||||||
|
|
||||||
|
(defn part-one [list-size input]
|
||||||
|
(->> (mapv parse-long (str/split input #","))
|
||||||
|
(map-indexed vector)
|
||||||
|
(reduce (fn [{:keys [data pos]}
|
||||||
|
[skip-size el]]
|
||||||
|
{:data (pinch-and-rotate data pos el)
|
||||||
|
:pos (+ pos skip-size el)})
|
||||||
|
{:data (vec (range list-size))
|
||||||
|
:pos 0})
|
||||||
|
:data
|
||||||
|
(take 2)
|
||||||
|
(apply *)))
|
||||||
|
(part-one 256 input)
|
||||||
|
(char 65)
|
||||||
|
|
||||||
|
(do
|
||||||
|
(def suffix [17, 31, 73, 47, 23])
|
||||||
|
(defn part-two [data lengths]
|
||||||
|
(let [lengths (vec (concat (map int lengths) suffix))]
|
||||||
|
(->> (reduce (fn [acc _]
|
||||||
|
(reduce (fn [{:keys [data pos skip]}
|
||||||
|
el]
|
||||||
|
{:data (pinch-and-rotate data pos el)
|
||||||
|
:skip (inc skip)
|
||||||
|
:pos (+ pos skip el)})
|
||||||
|
acc
|
||||||
|
lengths))
|
||||||
|
{:data (vec (concat data suffix))
|
||||||
|
:pos 0
|
||||||
|
:skip 0}
|
||||||
|
(range 64))
|
||||||
|
:data
|
||||||
|
#_(partition 16)
|
||||||
|
#_(map #(apply bit-xor %))
|
||||||
|
#_(map #(Long/toHexString %))
|
||||||
|
#_(apply str))))
|
||||||
|
(part-two (mapv parse-long (str/split input #",")) input))
|
||||||
|
(part-two (map int "1,2,3") [3 4 5 7])
|
||||||
Reference in New Issue
Block a user