Solve AOC day 3.1
This commit is contained in:
@@ -1,17 +1,15 @@
|
|||||||
(defun countChar [char str]
|
|
||||||
(count (str.split "") (lambda [c] ?(= c char))))
|
|
||||||
|
|
||||||
(defun parsePasswordCheck1 [:String ruleStr]
|
(defun parsePasswordCheck1 [:String ruleStr]
|
||||||
(let [[min max letter]
|
(let [[min max letter]
|
||||||
(.split (ruleStr.replace " " "-") "-")]
|
(.split (ruleStr.replace " " "-") "-")]
|
||||||
(lambda [password] (<= (Std.parseInt min) (countChar letter password) (Std.parseInt max)))))
|
(lambda [password] (<= (Std.parseInt min) (Util.countChar letter password) (Std.parseInt max)))))
|
||||||
|
|
||||||
(defun parsePasswordCheck2 [:String ruleStr]
|
(defun parsePasswordCheck2 [:String ruleStr]
|
||||||
(let [[a b letter]
|
(let [[a b letter]
|
||||||
(.split (ruleStr.replace " " "-") "-")
|
(.split (ruleStr.replace " " "-") "-")
|
||||||
aIdx (- (Std.parseInt a) 1)
|
aIdx (- (Std.parseInt a) 1)
|
||||||
bIdx (- (Std.parseInt b) 1)]
|
bIdx (- (Std.parseInt b) 1)]
|
||||||
(lambda [password] (= 1 (countChar letter (+ (.charAt password aIdx) (.charAt password bIdx)))))))
|
(lambda [password] (= 1 (Util.countChar letter (+ (.charAt password aIdx) (.charAt password bIdx)))))))
|
||||||
|
|
||||||
(defun validateInputLine [:String line ruleParser]
|
(defun validateInputLine [:String line ruleParser]
|
||||||
(let [[rule password]
|
(let [[rule password]
|
||||||
|
@@ -5,6 +5,7 @@ import StringTools;
|
|||||||
import kiss.Prelude;
|
import kiss.Prelude;
|
||||||
import year2020.Util;
|
import year2020.Util;
|
||||||
import year2020.Passwords;
|
import year2020.Passwords;
|
||||||
|
import year2020.Toboggan;
|
||||||
|
|
||||||
@:build(kiss.Kiss.build("src/year2020/Solutions.kiss"))
|
@:build(kiss.Kiss.build("src/year2020/Solutions.kiss"))
|
||||||
class Solutions {}
|
class Solutions {}
|
||||||
|
@@ -29,7 +29,24 @@
|
|||||||
(when (Passwords.validateInputLine "2-9 c: ccccccccc" Passwords.parsePasswordCheck2)
|
(when (Passwords.validateInputLine "2-9 c: ccccccccc" Passwords.parsePasswordCheck2)
|
||||||
(throw "parsePasswordCheck2 is broken"))
|
(throw "parsePasswordCheck2 is broken"))
|
||||||
(unless (= 673 (count (map (Util.readLines "src/year2020/inputs/day2-1.txt") (.bind Passwords.validateInputLine _ Passwords.parsePasswordCheck2)) (lambda [v] v)))
|
(unless (= 673 (count (map (Util.readLines "src/year2020/inputs/day2-1.txt") (.bind Passwords.validateInputLine _ Passwords.parsePasswordCheck2)) (lambda [v] v)))
|
||||||
(throw "parsePasswordCheck2 is broken")))
|
(throw "parsePasswordCheck2 is broken"))
|
||||||
|
|
||||||
|
// Day 3
|
||||||
|
(unless (= "..#.##.####" (Toboggan.pathString [
|
||||||
|
"..##......."
|
||||||
|
"#...#...#.."
|
||||||
|
".#....#..#."
|
||||||
|
"..#.#...#.#"
|
||||||
|
".#...##..#."
|
||||||
|
"..#.##....."
|
||||||
|
".#.#.#....#"
|
||||||
|
".#........#"
|
||||||
|
"#.##...#..."
|
||||||
|
"#...##....#"
|
||||||
|
".#..#...#.#"] 0 0 3 1))
|
||||||
|
(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")))
|
||||||
|
|
||||||
(defun :kiss.List<Int> pairWithSum [sum :kiss.List<Int> numbers]
|
(defun :kiss.List<Int> pairWithSum [sum :kiss.List<Int> numbers]
|
||||||
// Put the numbers in a map for random access. This gives an O(n) solution
|
// Put the numbers in a map for random access. This gives an O(n) solution
|
||||||
|
7
projects/advent-of-code/src/year2020/Toboggan.hx
Normal file
7
projects/advent-of-code/src/year2020/Toboggan.hx
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package year2020;
|
||||||
|
|
||||||
|
import kiss.Prelude;
|
||||||
|
import year2020.Util;
|
||||||
|
|
||||||
|
@:build(kiss.Kiss.build("src/year2020/Toboggan.kiss"))
|
||||||
|
class Toboggan {}
|
6
projects/advent-of-code/src/year2020/Toboggan.kiss
Normal file
6
projects/advent-of-code/src/year2020/Toboggan.kiss
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
(defun path [:kiss.List<String> hillTile x0 y0 dx dy]
|
||||||
|
(if (>= y0 .length hillTile)
|
||||||
|
[]
|
||||||
|
(.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) ""))
|
@@ -6,4 +6,7 @@
|
|||||||
StringTools.trim)
|
StringTools.trim)
|
||||||
(lambda [l] (< 0 l.length))))
|
(lambda [l] (< 0 l.length))))
|
||||||
|
|
||||||
(defun readInts [file] (let [lines (readLines file)] (lines.map Std.parseInt)))
|
(defun readInts [file] (let [lines (readLines file)] (lines.map Std.parseInt)))
|
||||||
|
|
||||||
|
(defun countChar [char str]
|
||||||
|
(count (str.split "") (lambda [c] ?(= c char))))
|
323
projects/advent-of-code/src/year2020/inputs/day3-1.txt
Normal file
323
projects/advent-of-code/src/year2020/inputs/day3-1.txt
Normal file
@@ -0,0 +1,323 @@
|
|||||||
|
.#..#.....#....##..............
|
||||||
|
...#.#...#...#.#..........#....
|
||||||
|
#...###...#.#.....#.##.#.#...#.
|
||||||
|
#.....#.#...##....#...#...#....
|
||||||
|
##.......##.#.....#........##.#
|
||||||
|
#..#....#......#..#......#...#.
|
||||||
|
#..#......#.......#............
|
||||||
|
##...#.#..#...#........#....##.
|
||||||
|
#.#.#...#...#..#........#....#.
|
||||||
|
.......#...........##......#...
|
||||||
|
##.##.##......#..#............#
|
||||||
|
..#.###..#..............#......
|
||||||
|
.##..#.....#......#.#..........
|
||||||
|
........#.........#....#....###
|
||||||
|
#..........#........#.#.#......
|
||||||
|
...##.....#..####.###..#.##....
|
||||||
|
....#...###............#..#....
|
||||||
|
...#.#...#.#...#..#.#........##
|
||||||
|
.....#...#.............#..#....
|
||||||
|
....#.#.#.##.....##.##....#....
|
||||||
|
..#....#............#.##.##..#.
|
||||||
|
.#..#..#................#...###
|
||||||
|
#..###.#..##..#............#...
|
||||||
|
.......#.#....#.##.#.##........
|
||||||
|
##...###.#....#...........###.#
|
||||||
|
...#.#....#..####.........#....
|
||||||
|
....##........#.#.#.###........
|
||||||
|
#...#..#.....#....##..#.##...#.
|
||||||
|
##....................##..#....
|
||||||
|
.#....##...........##...##...#.
|
||||||
|
.#.#..#.........#.........#.#.#
|
||||||
|
#.#..#.....#.#..#..#..#.#......
|
||||||
|
...#.............#......#....##
|
||||||
|
....#.#.......#....#...#.##...#
|
||||||
|
#.#.#..###..........#...#......
|
||||||
|
......#.....#..#..#.......##..#
|
||||||
|
.#......#......#.....#...#.....
|
||||||
|
......#..#......#.#............
|
||||||
|
..#............#..#....#.#.....
|
||||||
|
.....#..##.......#...##.###.#.#
|
||||||
|
.....#........##....#.#...##..#
|
||||||
|
..........##.#..#.#...#..#....#
|
||||||
|
#.#.#.#.##...................#.
|
||||||
|
.....#....##.....#..#...#..#...
|
||||||
|
...#....#.............#....#.#.
|
||||||
|
.........#.##..##..............
|
||||||
|
#...#.#....#..#...#.......#....
|
||||||
|
.#...#......#.##.#...#.#..###..
|
||||||
|
..#.#.#......#..#...##..##.##..
|
||||||
|
.........#.....#......##....##.
|
||||||
|
...###.......#..#........#.....
|
||||||
|
...#....#...#.#.#......##....#.
|
||||||
|
.#.....#......#...##.##..#.....
|
||||||
|
..#.##...#....####...##........
|
||||||
|
..#.#.###....#..##.......##....
|
||||||
|
.....#....##...#......#.......#
|
||||||
|
.#....#......#..............#..
|
||||||
|
.......#.#......#..#....#.#.#..
|
||||||
|
.......#.#.........###....#....
|
||||||
|
.#...#.......#.#..#..####....#.
|
||||||
|
..#...#.#......#..#.##.###..#..
|
||||||
|
..##.........#............#.#.#
|
||||||
|
#.........##.##.........#.###..
|
||||||
|
...#....#.......#..#..##.......
|
||||||
|
.#....##........##.......#..#..
|
||||||
|
...#.....#.#.##.#.#.....##.....
|
||||||
|
.#.#........#.......#.#..#..#..
|
||||||
|
.....####..##.##.#.#....#......
|
||||||
|
..#.##.#.#.#....###..#....#.#..
|
||||||
|
..##..#.#......##.#..#.........
|
||||||
|
....#..#.#.##.......#...##.....
|
||||||
|
....###.....#..###...#....###.#
|
||||||
|
..#....#.......#......#...##..#
|
||||||
|
..#..##......#....#.###..#..##.
|
||||||
|
..#..#...............#.#.#.....
|
||||||
|
...##...#.#..#.#...#......#....
|
||||||
|
#....#...#.#.#.#.#....#....#...
|
||||||
|
....##...#....#.....##..#.....#
|
||||||
|
......##.....#...##..#.......#.
|
||||||
|
......###......#....#.##..#....
|
||||||
|
.....#........#........#...#..#
|
||||||
|
.#..##.....##....#.#......#.#..
|
||||||
|
#..#.#.....#........#......#.#.
|
||||||
|
.#..#.##.....#####.#....#.#....
|
||||||
|
....##........#..........#.#...
|
||||||
|
.......#.....#.......#...#.#...
|
||||||
|
.#....#...##.###....#.#......#.
|
||||||
|
#...#...........##.#...........
|
||||||
|
#...##.......#..#........#.#..#
|
||||||
|
.....#..##..###....#.#.#....#..
|
||||||
|
..#..#.....#............#.#....
|
||||||
|
............#......#.....#.....
|
||||||
|
.#..#.....##.........#....###.#
|
||||||
|
#.........#....#....#.#..#...#.
|
||||||
|
##.#...##....#..#...#.#...#....
|
||||||
|
....###..##...................#
|
||||||
|
....##...#......#...#.#...#...#
|
||||||
|
#....#....###..........#...#..#
|
||||||
|
.....##.#....###.###....#..###.
|
||||||
|
#.....#...........#...........#
|
||||||
|
##..###.##........#..#.#..#.#..
|
||||||
|
.##...#..#.......#.#....#.....#
|
||||||
|
......##..#..#.......#.#...##..
|
||||||
|
......#..#..#.#...###..#.#....#
|
||||||
|
#.##.#..#......#...##........##
|
||||||
|
.....#..........##.....#...#...
|
||||||
|
........#....##......#......#.#
|
||||||
|
..#..#.#...#.#.#.......#......#
|
||||||
|
.#....#........#............#..
|
||||||
|
......##.....#...#.............
|
||||||
|
#......##..#.......##....##.#..
|
||||||
|
.....#..#..#...#.......#..#....
|
||||||
|
...#..##.#..#.#....##.....#..##
|
||||||
|
......#...#.#...#.#......###.#.
|
||||||
|
.#.#...#.....#..###.....#......
|
||||||
|
#..####.#....#.......##...#....
|
||||||
|
.##.......#.....#.........#....
|
||||||
|
#......##.#...............#....
|
||||||
|
.######.#...##...#...#...#..##.
|
||||||
|
....#...####....##.#..#...##...
|
||||||
|
.#...................#.#..#..#.
|
||||||
|
.#.#....##...#...#.#..#.#.#.#..
|
||||||
|
......#......#........##.#...#.
|
||||||
|
##..#...#..#.............##.#..
|
||||||
|
#.............#..........#.#...
|
||||||
|
...##.....#.............#......
|
||||||
|
......###.....#................
|
||||||
|
#.#.#....#..##.#.....#.........
|
||||||
|
.#.#........#.........#.#.##.#.
|
||||||
|
......#...##...#.#.....#....#..
|
||||||
|
#...#.........##.##.#..........
|
||||||
|
#..............#..#.......##...
|
||||||
|
#...#......#.#......#...#....#.
|
||||||
|
...#...#........#.#......#.###.
|
||||||
|
##.....#...#.#..#..#..#.......#
|
||||||
|
..#.##..##.........#...##.##...
|
||||||
|
#....#....#.....#..........#...
|
||||||
|
#.####..#..###.....#..#..#.....
|
||||||
|
..#.....#.##.##..####....#.#.#.
|
||||||
|
...#.#....#...#.......#..#.....
|
||||||
|
......###...#.#..#..#..........
|
||||||
|
.........#..#.....#.#.##......#
|
||||||
|
.......#.#....##.....##.#..#.#.
|
||||||
|
.#..#.#..#......##.###...##..#.
|
||||||
|
....###...........#.....#....#.
|
||||||
|
.#.##.....#..#.....#......##...
|
||||||
|
#..##....#..........#.##.##..#.
|
||||||
|
.###.#.#..#.#.....#..##....#.#.
|
||||||
|
..##.#....#.....##..#..........
|
||||||
|
##........#...#..#........###.#
|
||||||
|
#...#...........##.......#.#...
|
||||||
|
...###.....##.#....#...#...#...
|
||||||
|
......#....#.#.......###....#..
|
||||||
|
...#...#.......##.......###.#..
|
||||||
|
..............#.#..........##..
|
||||||
|
#.#....###..#..#.........#.....
|
||||||
|
.###.#.......#.....#....#.#....
|
||||||
|
.....###...#.#..#.#.......#....
|
||||||
|
.........#.##.#......#.#..#....
|
||||||
|
.......#....#....#.#....#..##.#
|
||||||
|
...............#...##.#..#.#..#
|
||||||
|
.....##........#..##...........
|
||||||
|
.##.#..#....#..#.#...#.........
|
||||||
|
.#.#..##.#..#......#....#.#...#
|
||||||
|
##....#.......##...........#...
|
||||||
|
..#...#.............#.#....#..#
|
||||||
|
..#......#..#.....#...##.....#.
|
||||||
|
....##...#.#...##...#..##......
|
||||||
|
.....#..#..........#...........
|
||||||
|
..##....#..#.#....#..#........#
|
||||||
|
.###....#.....#.#....#..##.....
|
||||||
|
#.......##.......#..#..#....#.#
|
||||||
|
.##..#...........#..##..##..#..
|
||||||
|
.#.................#...#....#..
|
||||||
|
.######.......#............##..
|
||||||
|
.#.........#......##.#.#.#.#.#.
|
||||||
|
.#.......#...#...#....###....#.
|
||||||
|
....#...##.#.#...#.....#.#..#..
|
||||||
|
.#..#..#...#.....###....#......
|
||||||
|
...#.##.###........#.....##....
|
||||||
|
..#....#.#.#..........#..#..#..
|
||||||
|
......#.....#...#..#..##..#.#..
|
||||||
|
#.#.......##.......#....#.....#
|
||||||
|
..#...#..#.#....#.##.##........
|
||||||
|
..#....#..##..#..##......#.....
|
||||||
|
#....#..##.....#....###........
|
||||||
|
##...#......#..###.#.....#.....
|
||||||
|
#..###....#...#...#...#......##
|
||||||
|
.....###....#......#..#..#...#.
|
||||||
|
.##......#.......##...#........
|
||||||
|
....#.#.....##.....#.....#.....
|
||||||
|
...##.#.....#..##...#...##.#...
|
||||||
|
..#...#.#....#....#...##.......
|
||||||
|
......#....#..#....#.#.........
|
||||||
|
..........#.#.#...##....#......
|
||||||
|
...#....................#..#...
|
||||||
|
...#....###....#..#.....#.....#
|
||||||
|
..#....#....#..#.#..##.#...#...
|
||||||
|
..#.##....##.....#.#........#..
|
||||||
|
#.....###..#.#.#...#..#....#...
|
||||||
|
........#..#.#..#........##....
|
||||||
|
.##....#................##.#.##
|
||||||
|
..##...#.#.#.....##..#....#....
|
||||||
|
....#..#....#..#........#..##..
|
||||||
|
...#...##....#....#..##......#.
|
||||||
|
##........#...#.....#.....#...#
|
||||||
|
.#......#....##...#.........##.
|
||||||
|
##........#...#.....#..#...#.#.
|
||||||
|
...##..#..#.....#..###.#..#....
|
||||||
|
....#..#..............#.......#
|
||||||
|
.......#.##...#......#.###.....
|
||||||
|
#........##..##....#.#.#.......
|
||||||
|
#.#..##.#.......#..##.....###..
|
||||||
|
.....##...#..#.....#...........
|
||||||
|
...#..#..#......#...#.#........
|
||||||
|
.#....#....#.#.....#.....#....#
|
||||||
|
...#..#...#..#.##.#......#.#.#.
|
||||||
|
..##....#..#..#.....#....#....#
|
||||||
|
...#....#.##.#..#.###......#...
|
||||||
|
.......#..#.....#.......#..#...
|
||||||
|
..###.#####..#..##.#.........#.
|
||||||
|
...#.......##...#.#..#.#......#
|
||||||
|
....#...#.###..#..........#....
|
||||||
|
...........#...#..##........#..
|
||||||
|
.......#...#....#....#.#..#....
|
||||||
|
.........#..........#...#....##
|
||||||
|
.##.........##..#.......##.#...
|
||||||
|
........#......###...##...#.#.#
|
||||||
|
#.#...##.##...........#...#.#..
|
||||||
|
.....###...#..##......#..#.....
|
||||||
|
#.#.....#.#....##..........#..#
|
||||||
|
#..#.......#.#.........####....
|
||||||
|
#.#...#.....#........#.....#..#
|
||||||
|
.....#..#.#.###.....#.#.###....
|
||||||
|
.###..#......##..#..#..........
|
||||||
|
#....#.#......#...#.##......#..
|
||||||
|
..#.........##.#.....#.........
|
||||||
|
...#....#.....##.#..#..##.#..#.
|
||||||
|
##.....#.#..#.#....#......#....
|
||||||
|
....###.#.....#.......#..#.#...
|
||||||
|
#.....##.....##...........#....
|
||||||
|
..........#..#......#.##...#...
|
||||||
|
#...#.###....##....#.###..###..
|
||||||
|
##........#.#...#..#.........#.
|
||||||
|
##........##.......#.....###...
|
||||||
|
.##....###........#..##...#...#
|
||||||
|
......#..##....##.....#..#.#...
|
||||||
|
.....#..##..#.......#.......#..
|
||||||
|
......#....#.......##.#........
|
||||||
|
.#.####.#..#......#..#.........
|
||||||
|
.##..#....#...##.#....#....#...
|
||||||
|
..#..#..#####.........#...#....
|
||||||
|
....#.....#.#.#.#...#.#......#.
|
||||||
|
....#...#.#..#.##...#...#......
|
||||||
|
..#...#...#...#...#..#.#.##..#.
|
||||||
|
..#......#.#.#.##.##.##..#.....
|
||||||
|
#..###......#.##...#....#.##.#.
|
||||||
|
.#.#.......##..##....##...##.#.
|
||||||
|
.##......##....##.#.......#...#
|
||||||
|
..#...#...................#....
|
||||||
|
.#...#.......######.....#.#..##
|
||||||
|
......#.##.....#.#.............
|
||||||
|
...........##.#........#..#....
|
||||||
|
#.............#.#.....#....##..
|
||||||
|
#...........#...#..###.....#...
|
||||||
|
....#.......#.#..#..#.#........
|
||||||
|
......#...##.......#..##....#..
|
||||||
|
......#.##.##..#........#.#...#
|
||||||
|
.#..#...##...................#.
|
||||||
|
.#.............#...#.#.#.#...#.
|
||||||
|
.........#.....#........#.#....
|
||||||
|
#..#...#.............##.#.....#
|
||||||
|
...#.#....#...##............#..
|
||||||
|
..#...#.##.###.#.....#......##.
|
||||||
|
...#.#..###...#.#............#.
|
||||||
|
...#....#........#.#...........
|
||||||
|
.#......#.#.#.........#.#....#.
|
||||||
|
....#..#......#.##.....#.#.....
|
||||||
|
..#..###....#....#.........###.
|
||||||
|
#..#.#....##.#....#.##..#......
|
||||||
|
#..#.....#.#.....##..#.##......
|
||||||
|
......#...#.#.............#..#.
|
||||||
|
#.#....#.#..#...#......#.#.....
|
||||||
|
..#.........#.#....#...#.......
|
||||||
|
.#..#.#...#....#...#......#...#
|
||||||
|
.......#........#.#..#..#...#..
|
||||||
|
..##.#......#..##.##.#..#..#...
|
||||||
|
.##...#....##.....#.....#...##.
|
||||||
|
#.....##.#....#.#......##..#...
|
||||||
|
.......#.#..#...#.......#.#...#
|
||||||
|
..#...#.......#...#..##........
|
||||||
|
#....##..#...#..#.#......#..#.#
|
||||||
|
##.#....#....#....#...#..#.##..
|
||||||
|
###........#.#..#..#......#....
|
||||||
|
.#......#.....#....#.#..#...#..
|
||||||
|
.#.....#.....#...##.......#..##
|
||||||
|
#..##.#..#..........#..........
|
||||||
|
...#.##.........#.#.##.#.......
|
||||||
|
.#..#...............#...#.#.#..
|
||||||
|
.....#.#.....#...####..#.....#.
|
||||||
|
.#....#.##..##...#...##.#...#.#
|
||||||
|
....#......##...#.#.#.....#.##.
|
||||||
|
#...#..#.#...#.#.....##...#....
|
||||||
|
..#..#....##..###......#..#....
|
||||||
|
.........#......##.....##....#.
|
||||||
|
.......#....#...#........###...
|
||||||
|
.....#..#..#...#...#......#....
|
||||||
|
..#..#...#.....#.....###..#.###
|
||||||
|
............#.#..#..#....#.....
|
||||||
|
...#..#...###.......#.......#..
|
||||||
|
#.........#........#.....##....
|
||||||
|
.#.#........#.....#........###.
|
||||||
|
....#.##.#...#.#.#.....#....#..
|
||||||
|
.##...#..#.......#.#...........
|
||||||
|
##...#.##...#...........#.....#
|
||||||
|
##....#.#.....##..#.......#....
|
||||||
|
##....#...#....#..#.......####.
|
||||||
|
......#...#..#.....#.#....#...#
|
||||||
|
.......#.....#..###............
|
||||||
|
#.#.#..#.....#.............#..#
|
||||||
|
.#..#.....##.....#...#.......##
|
||||||
|
..#.##........##...........#.#.
|
||||||
|
....##.#..###.#.........#...##.
|
Reference in New Issue
Block a user