Solve AOC day 2 pt 2
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package year2021;
|
||||
|
||||
import kiss.Prelude;
|
||||
import haxe.Constraints;
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
class Solutions2021 {}
|
||||
|
@@ -7,7 +7,8 @@
|
||||
(assert (= 1516 (countIncreases (for trio (slicesOf (Util.readInts "src/year2021/inputs/day1.txt") 3) (apply + trio))))))
|
||||
(day 2
|
||||
(load "day2.kiss")
|
||||
(print (apply * (simulateSubCommands (readSubCommands "src/year2021/inputs/day2.txt")))))
|
||||
(assert (= 2150351 (apply * (simulateSubCommands (readSubCommands "src/year2021/inputs/day2.txt")))))
|
||||
(assert (= 1842742223 (apply * (simulateSubCommands (readSubCommands "src/year2021/inputs/day2.txt") true)))))
|
||||
(dayTodo 3)
|
||||
(dayTodo 4)
|
||||
(dayTodo 5)
|
||||
|
@@ -9,12 +9,26 @@
|
||||
(var &mut :Int subX)
|
||||
(var &mut :Int subY)
|
||||
|
||||
(function simulateSubCommands [commands]
|
||||
(function simulateSubCommands [commands &opt fixed]
|
||||
(set subX 0)
|
||||
(set subY 0)
|
||||
(set aim 0)
|
||||
(set forward (if fixed forward2 forward1))
|
||||
(set down (if fixed down2 down1))
|
||||
(set up (if fixed up2 up1))
|
||||
(commands)
|
||||
[subX subY])
|
||||
|
||||
(function forward [x] (+= subX x))
|
||||
(function down [x] (+= subY x))
|
||||
(function up [x] (-= subY x))
|
||||
(var &mut :Function forward)
|
||||
(var &mut :Function down)
|
||||
(var &mut :Function up)
|
||||
|
||||
(function forward1 [x] (+= subX x))
|
||||
(function down1 [x] (+= subY x))
|
||||
(function up1 [x] (-= subY x))
|
||||
|
||||
(function forward2 [x] (+= subX x) (+= subY (* aim x)))
|
||||
(function down2 [x] (+= aim x))
|
||||
(function up2 [x] (-= aim x))
|
||||
|
||||
(var &mut :Int aim)
|
Reference in New Issue
Block a user