Fix AOC day 9 pt 1

This commit is contained in:
2021-12-10 11:24:13 -07:00
parent 936a55c814
commit 6de04b9fa8
3 changed files with 23 additions and 4 deletions

View File

@@ -5,6 +5,7 @@ import haxe.Constraints;
import haxe.ds.Option; import haxe.ds.Option;
import haxe.Int64; import haxe.Int64;
import haxe.Int64Helper; import haxe.Int64Helper;
import hx.strings.ansi.Ansi;
#if day4 #if day4
import year2021.Day4; import year2021.Day4;
#end #end

View File

@@ -55,8 +55,9 @@
(day 9 (day 9
(load "day9.kiss") (load "day9.kiss")
(assert (= 4 (count (lowPoints "src/year2021/inputs/day9-example.txt")))) (assert (= 4 (count (lowPoints "src/year2021/inputs/day9-example.txt"))))
(let [lp (lowPoints "src/year2021/inputs/day9.txt")] // (highlightLowPoints "src/year2021/inputs/day9.txt")
(doFor =>key val lp (print "$key : $val")))) (print (apply + (for =>_ height (lowPoints "src/year2021/inputs/day9.txt") (+ 1 height))))
)
(dayTodo 10) (dayTodo 10)
(dayTodo 11) (dayTodo 11)
(dayTodo 12) (dayTodo 12)

View File

@@ -42,7 +42,24 @@
(cond (cond
((> adjHeight height) ((> adjHeight height)
(pointsToCheck.remove adjKey)) (pointsToCheck.remove adjKey))
((< adjHeight height) ((<= adjHeight height)
(set isLow false)))) (set isLow false))))
(when isLow (dictSet lowPoints key height)))) (when isLow (dictSet lowPoints key height))))
lowPoints)) lowPoints))
(function :Void highlightLowPoints [file]
(let [writer (Ansi.writer (Sys.stdout))
m (lowPoints file)
lines (Util.readLines file)
&mut isRed false]
(doFor [y line] (enumerate lines)
(doFor [x height] (enumerate (line.split ""))
(if (m.exists (mapKey [x y]))
(unless isRed
(writer.fg RED)
(set isRed true))
(when isRed
(writer.fg WHITE)
(set isRed false)))
(writer.write height))
(writer.write "\n"))))