2020 day 20 part 1

This commit is contained in:
tristan 2020-12-20 21:55:24 +00:00
parent 2b036e11b7
commit be6a53c719
4 changed files with 1878 additions and 0 deletions

1727
2020/20/input.txt Normal file

File diff suppressed because it is too large Load diff

43
2020/20/part1.js Normal file
View file

@ -0,0 +1,43 @@
const fs = require('fs');
const input = fs.readFileSync('./input.txt', 'utf-8');
const inputTiles = input.split('\n\n');
// it is implied that the image is a square, which makes it far simpler.
const sideLength = Math.sqrt(inputTiles.length);
const tileSize = 9
let allBorders = new Map();
console.log(sideLength);
let tiles = [];
inputTiles.forEach(inputTile => {
tileLines = inputTile.split('\n');
let tileID = tileLines[0].slice(5, 9);
let tileData = tileLines.slice(1)
let borders = [
tileData[0],
tileData[tileSize],
tileData.reduce((a,b)=>a+b[0], ''),
tileData.reduce((a,b)=>a+b[tileSize], '')
];
borders.forEach(border=>{
if (!allBorders.has(border)) {
allBorders.set(border, 1)
} else {
allBorders.set(border, allBorders.get(border) + 1)
}
})
tiles.push({tileID, borders})
})
function reverseString(str) {
return (str === '') ? '' : reverseString(str.substr(1)) + str.charAt(0);
}
let runningTotal = 1;
tiles.forEach(tile => {
if (tile.borders.reduce((a, border) => a + allBorders.get(border) + (allBorders.get(reverseString(border))||0), -4) == 2) {
console.log(tile.tileID)
runningTotal *= tile.tileID
}
})
console.log(runningTotal)

107
2020/20/test.txt Normal file
View file

@ -0,0 +1,107 @@
Tile 2311:
..##.#..#.
##..#.....
#...##..#.
####.#...#
##.##.###.
##...#.###
.#.#.#..##
..#....#..
###...#.#.
..###..###
Tile 1951:
#.##...##.
#.####...#
.....#..##
#...######
.##.#....#
.###.#####
###.##.##.
.###....#.
..#.#..#.#
#...##.#..
Tile 1171:
####...##.
#..##.#..#
##.#..#.#.
.###.####.
..###.####
.##....##.
.#...####.
#.##.####.
####..#...
.....##...
Tile 1427:
###.##.#..
.#..#.##..
.#.##.#..#
#.#.#.##.#
....#...##
...##..##.
...#.#####
.#.####.#.
..#..###.#
..##.#..#.
Tile 1489:
##.#.#....
..##...#..
.##..##...
..#...#...
#####...#.
#..#.#.#.#
...#.#.#..
##.#...##.
..##.##.##
###.##.#..
Tile 2473:
#....####.
#..#.##...
#.##..#...
######.#.#
.#...#.#.#
.#########
.###.#..#.
########.#
##...##.#.
..###.#.#.
Tile 2971:
..#.#....#
#...###...
#.#.###...
##.##..#..
.#####..##
.#..####.#
#..#.#..#.
..####.###
..#.#.###.
...#.#.#.#
Tile 2729:
...#.#.#.#
####.#....
..#.#.....
....#..#.#
.##..##.#.
.#.####...
####.#.#..
##.####...
##..#.##..
#.##...##.
Tile 3079:
#.#.#####.
.#..######
..#.......
######....
####.#..#.
.#...#.##.
#.#####.##
..#.###...
..#.......
..#.###...

View file

@ -60,3 +60,4 @@ if (advent) {
17. [:star: :star:](https://adventofcode.com/2020/day/17 "see puzzle") 17. [:star: :star:](https://adventofcode.com/2020/day/17 "see puzzle")
18. [:star: :star:](https://adventofcode.com/2020/day/18 "see puzzle") 18. [:star: :star:](https://adventofcode.com/2020/day/18 "see puzzle")
19. [:star:](https://adventofcode.com/2020/day/19 "see puzzle") 19. [:star:](https://adventofcode.com/2020/day/19 "see puzzle")
20. [:star:](https://adventofcode.com/2020/day/20 "see puzzle")