Skip to content

Commit 9854293

Browse files
committed
day2
1 parent 4783d74 commit 9854293

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

resources/2019/day02

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,1,13,19,1,10,19,23,2,9,23,27,1,6,27,31,1,10,31,35,1,35,10,39,1,9,39,43,1,6,43,47,1,10,47,51,1,6,51,55,2,13,55,59,1,6,59,63,1,10,63,67,2,67,9,71,1,71,5,75,1,13,75,79,2,79,13,83,1,83,9,87,2,10,87,91,2,91,6,95,2,13,95,99,1,10,99,103,2,9,103,107,1,107,5,111,2,9,111,115,1,5,115,119,1,9,119,123,2,123,6,127,1,5,127,131,1,10,131,135,1,135,6,139,1,139,5,143,1,143,9,147,1,5,147,151,1,151,13,155,1,5,155,159,1,2,159,163,1,163,6,0,99,2,0,14,0

src/aoc19/day02.clj

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
(ns aoc19.day02
2+
(:require [clojure.java.io :as io]
3+
[clojure.string :as str]))
4+
5+
(def input (mapv #(Integer/valueOf %)
6+
(-> (io/resource "2019/day02")
7+
slurp
8+
str/trim
9+
(str/split #","))))
10+
11+
(defn output [noun verb]
12+
(first
13+
(loop [input (-> input
14+
(assoc 1 noun)
15+
(assoc 2 verb))
16+
pos 0]
17+
(let [p1 (input (+ pos 1))
18+
p2 (input (+ pos 2))
19+
p3 (input (+ pos 3))]
20+
(case (input pos)
21+
1 (recur (assoc input p3 (+ (input p1) (input p2))) (+ pos 4))
22+
2 (recur (assoc input p3 (* (input p1) (input p2))) (+ pos 4))
23+
99 input)))))
24+
25+
(output 12 2)
26+
; 11590668
27+
28+
(for [noun (range 100)
29+
verb (range 100)
30+
:when (= (output noun verb) 19690720)]
31+
(+ (* 100 noun) verb))
32+
; (2254)

0 commit comments

Comments
 (0)