Solve AOC day 2 pt 1

This commit is contained in:
2021-12-03 13:58:16 -07:00
parent 26c1c56cf0
commit 40882d7a45
3 changed files with 1023 additions and 1 deletions

View File

@@ -5,7 +5,9 @@
(day 1 (day 1
(assert (= 1475 (countIncreases (Util.readInts "src/year2021/inputs/day1.txt")))) (assert (= 1475 (countIncreases (Util.readInts "src/year2021/inputs/day1.txt"))))
(assert (= 1516 (countIncreases (for trio (slicesOf (Util.readInts "src/year2021/inputs/day1.txt") 3) (apply + trio)))))) (assert (= 1516 (countIncreases (for trio (slicesOf (Util.readInts "src/year2021/inputs/day1.txt") 3) (apply + trio))))))
(dayTodo 2) (day 2
(load "day2.kiss")
(print (apply * (simulateSubCommands (readSubCommands "src/year2021/inputs/day2.txt")))))
(dayTodo 3) (dayTodo 3)
(dayTodo 4) (dayTodo 4)
(dayTodo 5) (dayTodo 5)

View File

@@ -0,0 +1,20 @@
(defMacro readSubCommands [file &builder b]
(let [s (Stream.fromFile (eval file))
commands []]
(until (s.isEmpty)
(commands.push (b.call (read s) [(read s)]))
(s.dropWhitespace))
`(lambda [] ,(b.begin commands))))
(var &mut :Int subX)
(var &mut :Int subY)
(function simulateSubCommands [commands]
(set subX 0)
(set subY 0)
(commands)
[subX subY])
(function forward [x] (+= subX x))
(function down [x] (+= subY x))
(function up [x] (-= subY x))

File diff suppressed because it is too large Load Diff