solved day 3

This commit is contained in:
Joshua Seigler 2020-12-03 00:14:03 -05:00
parent eb884ec643
commit 9db2a69230
2 changed files with 349 additions and 7 deletions

View file

@ -0,0 +1,323 @@
............#....#.............
...........##....#......#..#..#
......#.......#......#.........
..#.#....#....#.............##.
..#........####....#...#.......
..##.....#.#.#..#.........#....
...#.#..#..#....#..#..#........
#.......#.........#....##.###..
......##..#.#...#.......#.#....
................##.........#.##
..##..........#...#.........#.#
..........#...##...............
#...#......#..#.#..#...##..#...
..##....#.......#......#..#....
....#......#......#....#.......
.........#.....#..#............
.#...#.#.........#........#....
#..........####.....#..........
......##.....#....#..#........#
#......#......#...........#....
....#.........#....#...#..#..#.
.#........#......#.#.....#.....
..#.#.#..........#....#.......#
......#.#........##....##....##
.....#.#..#...#................
......#......##...............#
..#..##.............#...##.....
......##......##..#......#.....
....#.............#..##.....##.
........#...............##.....
..#......#.##..#...#....#...#..
#......#.......#.............#.
.....#....##..............#....
#.#.........#....#..##....#....
.#...#...#....#.#............#.
...#...#.#..##.##.......##.....
......#..#....##..#.#..#..#....
.......##..#..#......#..#.....#
.##..#......#..........#....#..
.....#................#..#....#
........#..#....#.......#....#.
..#......#.......#......#....#.
....#...#.##........##....#....
.....#........#...........#....
...#....##..........#..#...#.#.
...#.......#......#...##...#...
.#.....#........#........#.#..#
.#.........#..##.....#.......#.
....#..#....#.......#......#...
.#.#...##..##................##
......#.#...#.......#....#....#
........#....#..#.....#......#.
.......#..........#......#.....
...............................
..#..#####..#..#..........#.#..
.....#....##................#.#
.................##............
.#...#...#..#...........#...##.
..#..#.#...........#.....##....
.#.......#.....#..##..#.#....#.
..........#.#......##...##.....
........##..#......##...#......
#......................#.......
............#.....#....#.#...#.
#......#..........##..#........
.........#.......#...#.#.......
...........##....#........#....
#........#.....#...#........##.
.#......##......#.##.......#..#
.....#......#.#......#.......#.
.....#.#.........#.............
...........#..#....#.....#.#...
...#............#...#..........
..#..#...#.....................
......#..#...#....#............
.#.#.#........#..#...#.........
..........#........#..#........
..............#...#....#.......
..#....#....##.......#...#.##..
.#.........#...#......#........
..#......#...#.........##.#...#
...#.....#...#..#.............#
.##........#.#.#.............#.
..#.............#..#.#...#....#
#...#.........#......#......#..
.......##..#.#..........#...#..
.......#.............#..#.#....
.#..#....#.#...................
....##...#..#....#..#..........
....#.#............#...........
###........##..#.#..#..........
.#.#.#.......#...........#..#.#
..........##..#.............#..
.#...........#......#.#..#..##.
...###......#.##........#.....#
....#..#..#...#................
...#.....#........#............
....#...#...#..#..##.##.......#
#.......#......#....#.......#..
#.............#...#............
##......#..#...#....##.#...#...
.##....................#....#..
..#.....#....#.#....#......#...
.......#..#..#............#...#
.#.....#.......#..#..#..#......
......##.......................
#..#...#.#.#....#.....#..#.....
...................#...#...#...
........#....##..#....#........
##......#.#......##.###........
.........#...##................
.......#...#...#.......##......
....#.......#......#.........##
....#....#.#..#.....#..........
...........#.......#........#..
..#.........###.#........#.....
.......#...........#.#.....##..
..#...#..#..........#..........
..........#.#....#.............
.##....#........##.............
.............#.#####........#.#
.................##...#........
##...#.#.......##........#.....
.#...#...#..#..#....#....#.....
..#...#........#..#............
##...#.#........#......##.#..##
.##......#..............##.#..#
.........#...#............#...#
....#..#....#...........#......
........#..#....#...##...#.....
..#..............#...#.#.....#.
.#.......#.#.....#..###.......#
...................#.......#...
........##.....#..#.......##...
.....#....................#...#
...#.#....#............#.#.....
#.......#.......#....#.........
..#...............#............
##...#...#...#..............#..
...#..........#..#....##.......
#............##.##......#.#.#..
.#...........#.........#....##.
..##....##.#....#.#.#.##...##.#
........#.#.#.............#....
.#...........#....##...#...#.#.
.##...#.................#......
....#.#..#....................#
.##......#........#..#.........
...#...............#...........
.#.#..##..##.#........#........
...........#....#.#.#......#...
...................#........#.#
..#............#...#.#........#
....#....#.#.##......#...#.....
..................#............
..........................#....
........#......................
......#.#...#.#..##......#.#.#.
.........#...#..#..............
..#.......#..........##..#.....
.........#............#........
......#..#..#...###....#....#..
#..#..............##.###..##..#
.#..................#.....#...#
........#........#........#....
.........#........#.##......#..
..#.....#.#..###...#....#......
..#................##....#.....
..#.#....##.....#......##...#..
...#.......#........##.........
#........#...#.#..........##..#
................#...#.#.....#..
.........#..#..#.#..#.#...#....
##....#...##.........#.#...#.##
....#..#.....##.....#.....##...
................#............#.
..#..#...#.....#......#.....##.
....#.......#...#...#...#..#...
....#..##....#.###.#...#..#....
#..##.....#.....#.##..##...##.#
.............###..........#....
..................#.....###....
..........#....#...#......#....
...#..##.......#......#.#...#..
..#.......................##.#.
..#..#..#....#......#...#...##.
#.............#................
..........#.#.#.........#.#....
.....##..#......##.#...........
.#.#.#.#....#.#...#.....#.#...#
......#.....##..............##.
#..#.......##..##..............
#..#..#................###.....
.....#......#.........#........
#...........#........#.#.......
#........#.#...#....#....###..#
###..#.#...........#.##.....#.#
..#..........#..#............#.
...#....#.......#..#.....###...
.#....#.##.#..###..............
.....#.##.##.......###.##...#.#
..#..##.......###..............
.#.........###..#..............
..................###.....#..#.
#....#....#.........#.....#....
.........#.#..#....#.....#.....
....##.......##.......#.#......
.....#...#.##.....#............
....#.#.#.......#..............
.##..#.#..#.......##...........
....#....##..#.....##.......#.#
.....##....#..#.#........#.....
........#.#.#....#....##...#..#
..#......#.#.#..#.##....#.#.#..
..#...#........#..#..........#.
.........#...................#.
........#.....##..#....#....#..
#..............#..........#....
#........#.#...........#.#.....
..#......................#.#..#
.........#.#.....#.#..........#
......#....#.#.##........#.....
.#....##......##..#...#.......#
..#........#...#.##....#..#.#..
.......#.....#..........#.....#
.........#.#..#.........#....#.
..........#.##.........##..#...
......#.#..#.....#.#..........#
......#.#.#..#..#.#............
...##.#..#..............#....#.
#..........#...................
.#....#..#.#.......#........#..
...#...#......#....#......#....
..#.#.......#.......#.......#.#
...#.#...#........#.....#......
#.......#..#...................
#..#..#.............#..#..#..#.
#.......................#....##
.#.........#....#....#.........
...............#...#..#....#..#
#.....#.#...#.#.....#..........
....##.#..#...#.#....###...#.#.
.................#....#........
####.......##...##.......#.##..
#..#....#....##............#...
..##......#..#........#........
....#..#..........#......#...##
..#.#.............#...........#
#...............#...#.......#.#
#..#.........#.##.#.......#...#
......#.....#.............#...#
......#.##.........##...#......
..#......##.#........#.......#.
#..#.........#.##..............
..#....#...#...#..#.....#.#....
................#.......#......
#.....#..............##....#.##
##.....#...#.#.....#..##...#...
#.#............##..........#..#
..#.##......#..#....#..........
....##.#....#.......##.....#...
......#.#....###...#...........
..................#......#....#
..............##...............
......#..#....#.....#..........
.......#........#...#..........
..#......#......##..#.##..#....
..#.#...#...............#......
....#.#.............#.#......#.
....#.#.....#......#..#.......#
........................#..#...
.................#...........#.
#......#......#.#.#.....##.....
..#....##...#.....##.#.....#..#
....#.........#....#.##.#.#....
..#....###.....................
.....#.#....#......#....##....#
#.......#...#......##.......#..
#....#.........##.....#........
#.....#...........#..#.....#...
.................#.....#..##..#
..#...#......####...##.........
...............................
#........#.....#...............
.#.........#....#.#......##....
...#..........#.........#.#.#.#
......##......#....###........#
.....................#.#.#.....
......#..#..#.......#...#......
...##.#.............#.#.......#
..#.#...#..#....#.....#.....#..
..#..#.....................#..#
........#....#..........#..#...
#.##....#..#.#..#............#.
..............###.............#
.#.#..........#.#....#...#....#
....#..........#.#..#......#...
.........##.#...#..............
..................#.....#.#....
.#....#.......#.##.#.........#.
.##..#...#......#..#...........
.#.........#..........#.#......
#.#......#.#.#.#.......#...#.#.
.......#....#.#......#......#..
...#..#....#.#..#..##...##.....
#.#.#.......#....#.........##..
#..#....#........###....#.#....
....#..#.........#....#...#....
...#.#.#.#..#..##.....#.##.....
.......#.......#...............
#.#.#......##....#.............
...#.##........#.....#...##.#..
...#.#.###..........#.......#..
.....#...#.......#.........#...
............#..#...#..##.......
...#....#..##.##..........#.##.
..................#........#...
....#.##.#.##........#.#.......
.#...........##.....##.......#.
#...#.........#.....##.........
#..#....#.#.........#..........
..#......#.#.#......#.....#..#.
..##......#..............#.....

View file

@ -4,20 +4,39 @@ const fromHere = position(__dirname)
const report = (...messages) => console.log(`[${require(fromHere('../../package.json')).logName} / ${__dirname.split(path.sep).pop()}]`, ...messages)
async function run () {
const input = (await read(fromHere('input.txt'), 'utf8')).trim()
const input = (await read(fromHere('input.txt'), 'utf8')).trim().split('\n')
await solveForFirstStar(input)
await solveForSecondStar(input)
}
async function solveForFirstStar (input) {
const solution = 'UNSOLVED'
// report('Input:', input);
report('Solution 1:', solution)
function slopeImpact (lines, delta) {
const width = lines[0].length
const pos = { x: 0, y: 0 }; let count = 0
while (pos.y < lines.length) {
if (lines[pos.y].charAt(pos.x) === '#') {
count++
}
pos.y += delta.y
pos.x += delta.x
pos.x %= width
}
return count
}
async function solveForSecondStar (input) {
const solution = 'UNSOLVED'
async function solveForFirstStar (lines) {
// report('lines:', lines);
report('Solution 1:', slopeImpact(lines, { x: 3, y: 1 }))
}
async function solveForSecondStar (lines) {
const solution = [
slopeImpact(lines, { x: 1, y: 1 }),
slopeImpact(lines, { x: 3, y: 1 }),
slopeImpact(lines, { x: 5, y: 1 }),
slopeImpact(lines, { x: 7, y: 1 }),
slopeImpact(lines, { x: 1, y: 2 })
].reduce((acc, cur) => acc * cur, 1)
report('Solution 2:', solution)
}