aboutsummaryrefslogtreecommitdiffstats
path: root/day24
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2022-11-30 19:55:31 -0500
committerClyne Sullivan <clyne@bitgloo.com>2022-11-30 19:55:31 -0500
commit8d43e37df99f280377bed90284d6ac2428334804 (patch)
tree3a5042c9af29da52b4bac38fd78b3ccde77a1dbc /day24
parent66ed0b9d27850dc653abc8baa75884f3de311bfa (diff)
move 2021 days to folder; update README
Diffstat (limited to 'day24')
-rw-r--r--day24/checker.clj47
-rw-r--r--day24/partboth.clj41
-rw-r--r--day24/solved-by-hand-with-help.md4
3 files changed, 0 insertions, 92 deletions
diff --git a/day24/checker.clj b/day24/checker.clj
deleted file mode 100644
index 4874f62..0000000
--- a/day24/checker.clj
+++ /dev/null
@@ -1,47 +0,0 @@
-(require '[clojure.string :as str])
-
-(defn alu-parse-argument [arg]
- (if (contains? #{\w \x \y \z} (first arg))
- (str/join ["@" arg])
- (read-string arg)))
-
-(defn alu-parse-instruction [[ins arg1 arg2]]
- (let [arg2-parsed (if (some? arg2) (alu-parse-argument arg2) 0)]
- (case ins
- "inp"
- (str/join ["(reset! " arg1 " (- (int (get input (swap! index inc))) 48))\n"])
- "add"
- (str/join ["(swap! " arg1 " +' " arg2-parsed ")\n"])
- "mul"
- (str/join ["(swap! " arg1 " *' " arg2-parsed ")\n"])
- "div"
- (str/join ["(swap! " arg1 " quot " arg2-parsed ")\n"])
- "mod"
- (str/join ["(swap! " arg1 " rem " arg2-parsed ")\n"])
- "eql"
- (str/join ["(swap! " arg1 " #(if (= % " arg2-parsed ") 1 0))\n"]))))
-
-(def alu-program-header
- "(defn alu-program [input]
- (let [index (atom -1) w (atom 0) x (atom 0) y (atom 0) z (atom 0)]\n")
-
-(defn alu-compile-program [instructions]
- (let [parsed-ins (mapv alu-parse-instruction instructions)]
- (eval (read-string
- (str/join [alu-program-header
- (str/join parsed-ins)
- "@z))"])))))
-
-(def program (->> (slurp "./in")
- str/split-lines
- (map #(str/split % #"\s+"))
- (alu-compile-program)))
-
-; to split by `inp w`s:
-; (partition 18)
-; (reverse)
-; (mapv alu-compile-program)))
-
-(println "Part 1:" (program "16181111641521"))
-(println "Part 2:" (program "59692994994998"))
-
diff --git a/day24/partboth.clj b/day24/partboth.clj
deleted file mode 100644
index 9548ec3..0000000
--- a/day24/partboth.clj
+++ /dev/null
@@ -1,41 +0,0 @@
-(require '[clojure.string :as str])
-
-; The given program operates on a base-26 stack, either pushing or
-; (conditionally) popping values. This code extracts those operations
-; from the input, then works through them to determine the highest
-; and lowest values that produce an output of zero.
-; See the .md file in this directory for more info.
-
-(def program (->> (slurp "./in")
- str/split-lines
- (map #(str/split % #"\s+"))
- (partition 18)
- (map (fn [step]
- (if (= "1" (last (nth step 4)))
- [:push (read-string (last (nth step 15)))]
- [:pop (read-string (last (nth step 5)))])
- ))))
-
-(defn program-index [prog] (- 14 (count prog)))
-
-(loop [numbers (vec (repeat 2 (vec (repeat 14 0))))
- stack '()
- prog program]
- (if-let [step (first prog)]
- (if (= :push (first step))
- (recur numbers
- (conj stack [(program-index prog) (second step)])
- (rest prog))
- (let [i2 (program-index prog)
- [i1 v] (first stack)
- diff (+ v (second step))]
- (recur
- [(if (neg? diff)
- (-> (first numbers) (assoc i1 9) (assoc i2 (+ 9 diff)))
- (-> (first numbers) (assoc i2 9) (assoc i1 (- 9 diff))))
- (if (neg? diff)
- (-> (second numbers) (assoc i2 1) (assoc i1 (- 1 diff)))
- (-> (second numbers) (assoc i1 1) (assoc i2 (+ 1 diff))))]
- (rest stack) (rest prog))))
- (println (map str/join numbers))))
-
diff --git a/day24/solved-by-hand-with-help.md b/day24/solved-by-hand-with-help.md
deleted file mode 100644
index 1ddf03e..0000000
--- a/day24/solved-by-hand-with-help.md
+++ /dev/null
@@ -1,4 +0,0 @@
-Went through this wonderful guide:
-
-[https://github.com/mrphlip/aoc/blob/master/2021/24.md](https://github.com/mrphlip/aoc/blob/master/2021/24.md)
-