Solve AOC day 2 pt 1
This commit is contained in:
@@ -5,7 +5,9 @@
|
||||
(day 1
|
||||
(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))))))
|
||||
(dayTodo 2)
|
||||
(day 2
|
||||
(load "day2.kiss")
|
||||
(print (apply * (simulateSubCommands (readSubCommands "src/year2021/inputs/day2.txt")))))
|
||||
(dayTodo 3)
|
||||
(dayTodo 4)
|
||||
(dayTodo 5)
|
||||
|
20
projects/aoc/src/year2021/day2.kiss
Normal file
20
projects/aoc/src/year2021/day2.kiss
Normal 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))
|
1000
projects/aoc/src/year2021/inputs/day2.txt
Normal file
1000
projects/aoc/src/year2021/inputs/day2.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user