Solve AOC Day 3.2

This commit is contained in:
2020-12-03 15:40:59 -07:00
parent 405570d82e
commit 133ebfd7c6
2 changed files with 32 additions and 13 deletions

View File

@@ -32,20 +32,37 @@
(throw "parsePasswordCheck2 is broken"))
// Day 3
(unless (= "..#.##.####" (Toboggan.pathString [
"..##......."
"#...#...#.."
".#....#..#."
"..#.#...#.#"
".#...##..#."
"..#.##....."
".#.#.#....#"
".#........#"
"#.##...#..."
"#...##....#"
".#..#...#.#"] 0 0 3 1))
(deflocal exampleHillTile [
"..##......."
"#...#...#.."
".#....#..#."
"..#.#...#.#"
".#...##..#."
"..#.##....."
".#.#.#....#"
".#........#"
"#.##...#..."
"#...##....#"
".#..#...#.#"])
(unless (= "..#.##.####" (Toboggan.pathString exampleHillTile 0 0 3 1))
(throw "Toboggan.path is broken"))
(unless (= 2 (Toboggan.pathTrees exampleHillTile 0 0 1 1))
(throw "Toboggan.path is broken"))
(unless (= 3 (Toboggan.pathTrees exampleHillTile 0 0 5 1))
(throw "Toboggan.path is broken"))
(unless (= 4 (Toboggan.pathTrees exampleHillTile 0 0 7 1))
(throw "Toboggan.path is broken"))
(unless (= 2 (Toboggan.pathTrees exampleHillTile 0 0 1 2))
(throw "Toboggan.path is broken"))
(unless (= 289 (Util.countChar "#" (Toboggan.pathString (Util.readLines "src/year2020/inputs/day3-1.txt") 0 0 3 1)))
(throw "Toboggan.path is broken"))
(unless (= 5522401584 (let [hillTile (Util.readLines "src/year2020/inputs/day3-1.txt")]
(*
(Toboggan.pathTrees hillTile 0 0 1 1)
(Toboggan.pathTrees hillTile 0 0 3 1)
(Toboggan.pathTrees hillTile 0 0 5 1)
(Toboggan.pathTrees hillTile 0 0 7 1)
(Toboggan.pathTrees hillTile 0 0 1 2))))
(throw "Toboggan.path is broken")))
(defun :kiss.List<Int> pairWithSum [sum :kiss.List<Int> numbers]

View File

@@ -3,4 +3,6 @@
[]
(.concat [(.charAt (nth hillTile y0) (Math.floor (% x0 .length (nth hillTile y0))))] (path hillTile (+ x0 dx) (+ y0 dy) dx dy))))
(defun pathString [:kiss.List<String> hillTile x0 y0 dx dy] (.join (path hillTile x0 y0 dx dy) ""))
(defun pathString [:kiss.List<String> hillTile x0 y0 dx dy] (.join (path hillTile x0 y0 dx dy) ""))
(defun pathTrees [:kiss.List<String> hillTile x0 y0 dx dy] (Util.countChar "#" (pathString hillTile x0 y0 dx dy)))