diff --git a/solutions/day3/input.txt b/solutions/day3/input.txt index e69de29..a961897 100644 --- a/solutions/day3/input.txt +++ b/solutions/day3/input.txt @@ -0,0 +1,323 @@ +............#....#............. +...........##....#......#..#..# +......#.......#......#......... +..#.#....#....#.............##. +..#........####....#...#....... +..##.....#.#.#..#.........#.... +...#.#..#..#....#..#..#........ +#.......#.........#....##.###.. +......##..#.#...#.......#.#.... +................##.........#.## +..##..........#...#.........#.# +..........#...##............... +#...#......#..#.#..#...##..#... +..##....#.......#......#..#.... +....#......#......#....#....... +.........#.....#..#............ +.#...#.#.........#........#.... +#..........####.....#.......... +......##.....#....#..#........# +#......#......#...........#.... +....#.........#....#...#..#..#. +.#........#......#.#.....#..... +..#.#.#..........#....#.......# +......#.#........##....##....## +.....#.#..#...#................ +......#......##...............# +..#..##.............#...##..... +......##......##..#......#..... +....#.............#..##.....##. +........#...............##..... +..#......#.##..#...#....#...#.. +#......#.......#.............#. +.....#....##..............#.... +#.#.........#....#..##....#.... +.#...#...#....#.#............#. +...#...#.#..##.##.......##..... +......#..#....##..#.#..#..#.... +.......##..#..#......#..#.....# +.##..#......#..........#....#.. +.....#................#..#....# +........#..#....#.......#....#. +..#......#.......#......#....#. +....#...#.##........##....#.... +.....#........#...........#.... +...#....##..........#..#...#.#. +...#.......#......#...##...#... +.#.....#........#........#.#..# +.#.........#..##.....#.......#. +....#..#....#.......#......#... +.#.#...##..##................## +......#.#...#.......#....#....# +........#....#..#.....#......#. +.......#..........#......#..... +............................... +..#..#####..#..#..........#.#.. +.....#....##................#.# +.................##............ +.#...#...#..#...........#...##. +..#..#.#...........#.....##.... +.#.......#.....#..##..#.#....#. +..........#.#......##...##..... +........##..#......##...#...... +#......................#....... +............#.....#....#.#...#. +#......#..........##..#........ +.........#.......#...#.#....... +...........##....#........#.... +#........#.....#...#........##. +.#......##......#.##.......#..# +.....#......#.#......#.......#. +.....#.#.........#............. +...........#..#....#.....#.#... +...#............#...#.......... +..#..#...#..................... +......#..#...#....#............ +.#.#.#........#..#...#......... +..........#........#..#........ +..............#...#....#....... +..#....#....##.......#...#.##.. +.#.........#...#......#........ +..#......#...#.........##.#...# +...#.....#...#..#.............# +.##........#.#.#.............#. +..#.............#..#.#...#....# +#...#.........#......#......#.. +.......##..#.#..........#...#.. +.......#.............#..#.#.... +.#..#....#.#................... +....##...#..#....#..#.......... +....#.#............#........... +###........##..#.#..#.......... +.#.#.#.......#...........#..#.# +..........##..#.............#.. +.#...........#......#.#..#..##. +...###......#.##........#.....# +....#..#..#...#................ +...#.....#........#............ +....#...#...#..#..##.##.......# +#.......#......#....#.......#.. +#.............#...#............ +##......#..#...#....##.#...#... +.##....................#....#.. +..#.....#....#.#....#......#... +.......#..#..#............#...# +.#.....#.......#..#..#..#...... +......##....................... +#..#...#.#.#....#.....#..#..... +...................#...#...#... +........#....##..#....#........ +##......#.#......##.###........ +.........#...##................ +.......#...#...#.......##...... +....#.......#......#.........## +....#....#.#..#.....#.......... +...........#.......#........#.. +..#.........###.#........#..... +.......#...........#.#.....##.. +..#...#..#..........#.......... +..........#.#....#............. +.##....#........##............. +.............#.#####........#.# +.................##...#........ +##...#.#.......##........#..... +.#...#...#..#..#....#....#..... +..#...#........#..#............ +##...#.#........#......##.#..## +.##......#..............##.#..# +.........#...#............#...# +....#..#....#...........#...... +........#..#....#...##...#..... +..#..............#...#.#.....#. +.#.......#.#.....#..###.......# +...................#.......#... +........##.....#..#.......##... +.....#....................#...# +...#.#....#............#.#..... +#.......#.......#....#......... +..#...............#............ +##...#...#...#..............#.. +...#..........#..#....##....... +#............##.##......#.#.#.. +.#...........#.........#....##. +..##....##.#....#.#.#.##...##.# +........#.#.#.............#.... +.#...........#....##...#...#.#. +.##...#.................#...... +....#.#..#....................# +.##......#........#..#......... +...#...............#........... +.#.#..##..##.#........#........ +...........#....#.#.#......#... +...................#........#.# +..#............#...#.#........# +....#....#.#.##......#...#..... +..................#............ +..........................#.... +........#...................... +......#.#...#.#..##......#.#.#. +.........#...#..#.............. +..#.......#..........##..#..... +.........#............#........ +......#..#..#...###....#....#.. +#..#..............##.###..##..# +.#..................#.....#...# +........#........#........#.... +.........#........#.##......#.. +..#.....#.#..###...#....#...... +..#................##....#..... +..#.#....##.....#......##...#.. +...#.......#........##......... +#........#...#.#..........##..# +................#...#.#.....#.. +.........#..#..#.#..#.#...#.... +##....#...##.........#.#...#.## +....#..#.....##.....#.....##... +................#............#. +..#..#...#.....#......#.....##. +....#.......#...#...#...#..#... +....#..##....#.###.#...#..#.... +#..##.....#.....#.##..##...##.# +.............###..........#.... +..................#.....###.... +..........#....#...#......#.... +...#..##.......#......#.#...#.. +..#.......................##.#. +..#..#..#....#......#...#...##. +#.............#................ +..........#.#.#.........#.#.... +.....##..#......##.#........... +.#.#.#.#....#.#...#.....#.#...# +......#.....##..............##. +#..#.......##..##.............. +#..#..#................###..... +.....#......#.........#........ +#...........#........#.#....... +#........#.#...#....#....###..# +###..#.#...........#.##.....#.# +..#..........#..#............#. +...#....#.......#..#.....###... +.#....#.##.#..###.............. +.....#.##.##.......###.##...#.# +..#..##.......###.............. +.#.........###..#.............. +..................###.....#..#. +#....#....#.........#.....#.... +.........#.#..#....#.....#..... +....##.......##.......#.#...... +.....#...#.##.....#............ +....#.#.#.......#.............. +.##..#.#..#.......##........... +....#....##..#.....##.......#.# +.....##....#..#.#........#..... +........#.#.#....#....##...#..# +..#......#.#.#..#.##....#.#.#.. +..#...#........#..#..........#. +.........#...................#. +........#.....##..#....#....#.. +#..............#..........#.... +#........#.#...........#.#..... +..#......................#.#..# +.........#.#.....#.#..........# +......#....#.#.##........#..... +.#....##......##..#...#.......# +..#........#...#.##....#..#.#.. +.......#.....#..........#.....# +.........#.#..#.........#....#. +..........#.##.........##..#... +......#.#..#.....#.#..........# +......#.#.#..#..#.#............ +...##.#..#..............#....#. +#..........#................... +.#....#..#.#.......#........#.. +...#...#......#....#......#.... +..#.#.......#.......#.......#.# +...#.#...#........#.....#...... +#.......#..#................... +#..#..#.............#..#..#..#. +#.......................#....## +.#.........#....#....#......... +...............#...#..#....#..# +#.....#.#...#.#.....#.......... +....##.#..#...#.#....###...#.#. +.................#....#........ +####.......##...##.......#.##.. +#..#....#....##............#... +..##......#..#........#........ +....#..#..........#......#...## +..#.#.............#...........# +#...............#...#.......#.# +#..#.........#.##.#.......#...# +......#.....#.............#...# +......#.##.........##...#...... +..#......##.#........#.......#. +#..#.........#.##.............. +..#....#...#...#..#.....#.#.... +................#.......#...... +#.....#..............##....#.## +##.....#...#.#.....#..##...#... +#.#............##..........#..# +..#.##......#..#....#.......... +....##.#....#.......##.....#... +......#.#....###...#........... +..................#......#....# +..............##............... +......#..#....#.....#.......... +.......#........#...#.......... +..#......#......##..#.##..#.... +..#.#...#...............#...... +....#.#.............#.#......#. +....#.#.....#......#..#.......# +........................#..#... +.................#...........#. +#......#......#.#.#.....##..... +..#....##...#.....##.#.....#..# +....#.........#....#.##.#.#.... +..#....###..................... +.....#.#....#......#....##....# +#.......#...#......##.......#.. +#....#.........##.....#........ +#.....#...........#..#.....#... +.................#.....#..##..# +..#...#......####...##......... +............................... +#........#.....#............... +.#.........#....#.#......##.... +...#..........#.........#.#.#.# +......##......#....###........# +.....................#.#.#..... +......#..#..#.......#...#...... +...##.#.............#.#.......# +..#.#...#..#....#.....#.....#.. +..#..#.....................#..# +........#....#..........#..#... +#.##....#..#.#..#............#. +..............###.............# +.#.#..........#.#....#...#....# +....#..........#.#..#......#... +.........##.#...#.............. +..................#.....#.#.... +.#....#.......#.##.#.........#. +.##..#...#......#..#........... +.#.........#..........#.#...... +#.#......#.#.#.#.......#...#.#. +.......#....#.#......#......#.. +...#..#....#.#..#..##...##..... +#.#.#.......#....#.........##.. +#..#....#........###....#.#.... +....#..#.........#....#...#.... +...#.#.#.#..#..##.....#.##..... +.......#.......#............... +#.#.#......##....#............. +...#.##........#.....#...##.#.. +...#.#.###..........#.......#.. +.....#...#.......#.........#... +............#..#...#..##....... +...#....#..##.##..........#.##. +..................#........#... +....#.##.#.##........#.#....... +.#...........##.....##.......#. +#...#.........#.....##......... +#..#....#.#.........#.......... +..#......#.#.#......#.....#..#. +..##......#..............#..... diff --git a/solutions/day3/solution.js b/solutions/day3/solution.js index bcee989..15cd1ec 100644 --- a/solutions/day3/solution.js +++ b/solutions/day3/solution.js @@ -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) }