diff options
author | 2020-12-07 22:53:36 +0100 | |
---|---|---|
committer | 2020-12-07 22:53:36 +0100 | |
commit | 3700a9063725b001267730d6586d9cf905476cbb (patch) | |
tree | ea80cec1f3c24a940abf0527981625bec08a46e8 /day3 | |
parent | 5e34312e42721aae0d8919df7ef31ffaff435555 (diff) | |
download | advent_of_code_2020-3700a9063725b001267730d6586d9cf905476cbb.tar.gz advent_of_code_2020-3700a9063725b001267730d6586d9cf905476cbb.tar.bz2 advent_of_code_2020-3700a9063725b001267730d6586d9cf905476cbb.zip |
day3
Diffstat (limited to 'day3')
-rw-r--r-- | day3/data.js | 327 | ||||
-rw-r--r-- | day3/day3-1.js | 9 | ||||
-rw-r--r-- | day3/day3-2.js | 12 |
3 files changed, 348 insertions, 0 deletions
diff --git a/day3/data.js b/day3/data.js new file mode 100644 index 0000000..be1b75d --- /dev/null +++ b/day3/data.js @@ -0,0 +1,327 @@ +const data = [ + "....#...##.#.........#....#....", + "#.......#...#...#.#............", + "#..#..#.#.##....#.#........#...", + "........##...................#.", + "........#...##...#.#.###.......", + "##............#...#.....#.##...", + "...........#....###...#.....#..", + ".......#......#..##..#.....#...", + "..#.#..#....#.........#...#..#.", + ".........##......#.....##..##..", + "........#.....#....#..##......#", + "..#..#.......#..............#..", + ".....#.#.......................", + ".#.#....#.........#............", + ".......#.....#.###.............", + "......##......#...........#..#.", + ".#...............##...#........", + ".....#..##........###.........#", + "#...........#..#............#..", + ".........#....#..#.#......#....", + ".......#.........#..##.........", + ".##.....#..................#...", + "....#............#.#....#.....#", + "..#....#...##....#...#.#...#...", + "..........#................#.#.", + "#...#.#.#.####..#.#..........#.", + "..#...#.##......#...........#..", + "..#.....#...#.......#......#..#", + "..............#.......#........", + ".#..#..........#.....#...#..#.#", + "#........#...#......#.......#..", + "#..................#...........", + "..#...#........#...#..#........", + "..............#.....#.....#..#.", + "#.#.......#..............##.##.", + "....#.#.....##....#...........#", + "......#....#...#..#.......#....", + "....#..#.#.....#..##.....#....#", + "...........#.......#.#.#.......", + "#.......#..##........#..#......", + ".........#.##..#..............#", + "...........#............###.#..", + "..#.....#.....##...#.........#.", + "....##............##........#..", + ".....###..........#......##....", + "#...##..#..#..........#........", + "....#.....#.......#..#.#...##..", + ".#....#........#.#.........#.#.", + "##...#.#.....#......#..........", + ".....##.....#....#.....###.#..#", + "..............#..###..#...#..#.", + "....#...#....#.............#.#.", + ".#.........#.....#........#.##.", + "....#.........#..........#.....", + ".......#........#.#.#..........", + "#........##....#.........#.....", + "..##..........#....#.#...#....#", + "#...#.#......#..##..........#.#", + ".....#..#...#..#...............", + "#...#..............#...........", + ".#...#....#..##.....#....#.#...", + ".#...#.......#...#..#.##....#..", + "#....#........#....#...#.......", + "#..#......#.....#.....#..##....", + "......#.#....##....##..#...#...", + "..#....#.#.###..............#..", + ".#.##.......#.#.#..#...#..#....", + "..#..........#.#....#..#.#....#", + "..........#...#...#..........#.", + "..........#.....#.#..#..#....##", + ".#.#...##...#...........####...", + "........##..#.#..........#.##.#", + "#......###...........#...#.....", + "..#.#....##.........##....#....", + "#....#.##..##..#..#.....#.....#", + ".##.....##....##....#.......#..", + "#...#.....##....#..........#...", + "............#.#.##....#....#...", + "....#............#.....#......#", + "....................#..........", + "..#....................#..#....", + "....#.....#........#..##...#...", + "#.....#.#....................##", + ".#....#.#.#...#..........#....#", + "....#...#......#...#.....##...#", + ".....#.........................", + ".......#..#.#...#...#...#.....#", + "...#......#.##.#...#..#...##.#.", + "...........................#..#", + "..#.#.....#........##..........", + "....#...##........#.#.#..#...##", + "..##.....#..###.........##.##..", + ".#..#.....#...#.............#..", + "#..............##...#....##....", + ".##......#.#............#......", + ".............##...#.#.......#..", + ".........#..#..#...............", + "........##......#....##........", + "...#.........#.#.#.............", + "#..........#......#......#..#..", + ".............##.#.#..#.#.#...#.", + ".....#.........#...............", + "..##.#..#.....##..#........#.#.", + ".#..........#.#.......#......##", + ".#........................#....", + "#....#....#...#..#......#......", + "........#.......#......#.....#.", + ".....#....##..#...###...#....#.", + "....#.........#....#......#....", + ".............#...#....#.......#", + ".....#.........#..#.#..........", + ".........#..#........#.#.#.....", + "......#.##......#....#.#.##.#..", + ".#...#.#...#...#.#......#....##", + ".#................#......#.....", + "#.#.#...............#..........", + ".....#.#.......#...#........#..", + "#...#.#.#.##..#...........#..#.", + ".............###.........#....#", + ".#.....#.......##....##.......#", + "....#...#.......#.##.....#.....", + "...........##.........#...#....", + "..............#.#..#.....#..#..", + "#.#...#..#.#.........#......#.#", + "#.##.....##....#........#.#.#.#", + "##.#.###.........##.......#..#.", + "#.....#.....................#..", + ".........##........#...........", + ".###........##....#...#........", + "....#.#........##...........#..", + "..........#.....#..........#..#", + "......#..............#......#..", + ".....#...#......#...#...#......", + "..........#.#..#....#...#..###.", + "#..##........#................#", + "..#............................", + ".....#.........#.#.............", + "........#...#.....#...##......#", + "..#........#................#..", + "......#....#..#......#.........", + "...........##....#..#.#........", + ".....#.............###.........", + "#............#......#..#.......", + "..#..#.................#..#..##", + ".......#......#.....#........#.", + "....................#..#.##...#", + ".#..##...............##...#....", + "...#...#....#........#.........", + ".....##...#.....###............", + ".###.........#........#.....##.", + ".............#...#.............", + "...#.#...............#..##..#.#", + "...#...............#..#.....#..", + "....#.#..................#...#.", + "..........#...........#.#...###", + "#...#......#................#..", + "...#.#.......#...#......#.##...", + "......#..........#.............", + "##.......#.##.#...........#....", + "......#...#.#.....#............", + ".#.....#.....#.....#.........#.", + "..................#............", + ".#.#.#.....#......#.##.........", + ".......#..##.##......#..#....#.", + "...#.#.#......#...#........#...", + "..#............#......#.......#", + "..#......#........#.........#..", + "..#..#.#.#.....#.............#.", + "..#.#..##......#...#...##......", + ".##...#....##.#.#...........#..", + "..............#..#...#....#....", + ".......#.#........#............", + ".....##..###........#..........", + "......................#........", + "..##....#....#.................", + ".##.#.###.#........#.##..#...#.", + "##................#...........#", + "....#..##.....##...............", + ".#.....#..#............#.....#.", + "#.........#..............#.....", + "...##.#......#...#.............", + "................#..............", + "...#.....#....##...#..#....#...", + "..............##..#...#.##..#..", + "......................#..#....#", + ".......#....#..#.##.........#.#", + "#...#........##.......#........", + "...##...............#.....#....", + ".##...##...#...................", + ".........##.#...#.........#....", + "............#............#..#..", + ".............................#.", + "....#.#....#...................", + "......#......#...#..##.........", + "#........#.#.#.#.#......#....#.", + ".#.........#.#...#......#..#.#.", + "..............#....##.........#", + ".#.......#..#....#.#.#....#....", + "...###.#.#..#...#....#....#....", + "#........#....................#", + "......#...##.###..#..##...#....", + ".....#........#.......#........", + "#..#...........#.#.............", + "....##.#...#..##............##.", + "#.#..##..#...#...#.....#.......", + "..#.............#.##..#...#.##.", + ".#.....##.#..#...#...........#.", + "....#...#....................##", + "....##......#.###......#......#", + "...#...#.........#..#.##....#..", + "#......#..#....###.........#...", + "#...........##.............#.#.", + "#..............##....#......#..", + ".........#...#.#...#...#.......", + "....#....#............#.......#", + "........#...#....#......##.....", + "..........#.#..#.........#.....", + "#........#.##....##......#.....", + "...#.......#...................", + "###...#...#..#.##....#.....#...", + "........##..........#.##..#....", + ".....#......#..#.....#.....#.#.", + "...#..#..##..###.....##.#......", + "#..#......##...#............#..", + "#............#....#..#.........", + "#........#.......#......#..##.#", + "...#.#.........#.#.............", + "#..............#..............#", + "#.#......#..........##.........", + "#..##...........#..##...#......", + ".....#.#.....#......#.....#.#.#", + ".#.##...#...##...........#....#", + "#.............#........#.......", + "..##.............#...#.........", + "....#.#......###....#..........", + "...#..#.....#..##.#....#...#.#.", + ".............##................", + "#.#............#........#..#.#.", + ".#......#.....#...........#....", + "...#.........#...........#.##..", + ".....#...#.....#..#..........#.", + "........#.#...............#.#..", + ".......#..#..#.....#.......##..", + ".#...#...#..#...##...#.........", + "..........##....#..#.##..#.....", + "....#.................#...#....", + ".........#...#......#....#....#", + ".........#..#...#.##........##.", + "#.#....##.......#.#............", + "##.......##..................#.", + "......#...#......##............", + "##.#...#.#...........#..#......", + ".........#.........#..#.#...#..", + ".#...#.......#.#...###.........", + "................#.#.....#......", + "..#...#.....#........#.........", + ".........##.###.#.#.....#...#..", + "#..#..........#....#.#...#...##", + "##.#.#....#..##.............#.#", + ".###....#..#...............##..", + "............#......#.#.#....#..", + "........#...#..#...#...........", + "##.........#................#..", + "...###...#.#..#...#..........##", + "...#......#......##........#...", + ".......#............#..........", + ".....#.....##....#.....###.....", + ".#...#...#.....#..#..#....#..#.", + "#.#........#..#.......##...#.##", + ".....#.....##..#.##........#..#", + ".....#...#...........#.........", + "..#....#.#...#..#....##...#...#", + "...........#...##.........#....", + "..#....#....##........#.####...", + "#.............#.#.............#", + "...................#.....#.#..#", + ".#....#.#.............#.#......", + "#...........#............#.#...", + "..#.........#.#....#.......##..", + "#....####......#...#......#....", + "....##....#...................#", + "....#.##....#.............#....", + ".........##........#.....#..#..", + "............#...#..............", + "............#..##....#.....##.#", + "............#.....#......#.....", + "........#..#........##.#.......", + "...#.#........#..............#.", + "............#.........#..#.#...", + "................#.............#", + "..##..........##......#.#......", + "..#..#.##....#.........#...#...", + "...........##...#.#.#..........", + ".#.#.......#.#...#.........#...", + ".........#..#........#..#.#....", + "..........##..#.##....#....#...", + "....#...............#.......#..", + "##..........##.................", + "....#.#.#.....#..........##.#..", + "..............#.##..........##.", + "##...............#...#..#......", + "..#..#..........#......#.......", + "#...#..##.#.#..................", + "....#....##......##.#...#....##", + ".#...#.#....##.............#..#", + "................#......###.....", + "..#..#.............#.#.......#.", + "..#..................#.......#.", + ".....#.......#....#.##...#.##..", + ".....##.......#......#..#......", + "#..#.......#........#..........", + "..#...#..#....#.........#......", + "#..#..#......##..#.##....####..", + "......##.#.....#..#.......#....", + ".##...#.....#..#...#.#.........", + "#.....#........###....#...#..#.", + ".#....#.#..#......#............", + ".........#..#..#.....#........#", + "..#.......#..........#..#......", + "......#.......##.#....#.#.#....", + ".#............#.....#.......#..", + "...#..#...............#........", + ".....#.........................", +]; + +module.exports = data diff --git a/day3/day3-1.js b/day3/day3-1.js new file mode 100644 index 0000000..401ac7f --- /dev/null +++ b/day3/day3-1.js @@ -0,0 +1,9 @@ +const data = require('./data') + +let trees = 0; +data.forEach((line, i) => { + line[(3 * i)%line.length] === "#" && (trees += 1) +}) + +console.log(trees) + diff --git a/day3/day3-2.js b/day3/day3-2.js new file mode 100644 index 0000000..a0c558d --- /dev/null +++ b/day3/day3-2.js @@ -0,0 +1,12 @@ +const data = require('./data') +const check = (x, y) => { + let trees = 0, turn = 0; + for(i=0; i<data.length; i=i+y) { + turn !== 0 && data[i][(x * turn)%data[i].length] === "#" && (trees += 1) + turn += 1 + } + return trees +} + +console.log(check(1,1) * check(3,1) * check(5,1) * check(7,1) * check(1,2)) + |