diff --git a/2020/05/input b/2020/05/input new file mode 100644 index 0000000..e4a4418 --- /dev/null +++ b/2020/05/input @@ -0,0 +1,843 @@ +BBFFBBFLRL +BFFFBBBRLL +FFBBFFFLLR +FBFBFFBRRL +FBBBBBFLLR +BFBBFFBLRL +BFBBFBFRRL +BFBFFBBLLL +BFBFFFBRLL +FFFBFBFLLL +BFBFBBBLRR +BFBBFBFRLR +FFFBBBBLLL +BFFBFFFLLR +BBFBFBBLLL +BFFFBBBRRR +FBBFFBFRLR +BFFFFBBRRR +FFBFFFBLLL +BBFFFFBRRL +BFFFFFBLRL +BBFBBBBLRR +FBBFBFBRLR +BFBFFFBRRL +BBFFFBBLRR +BBFBBFFRRR +FFBBFBBLLR +BFBFFFBLLL +BFFBBBBLRR +FBBBBFBLRL +BBFBFBFRRR +BFFFBFBLRR +BBFFFBBRRL +FFBFBBBRLR +BFFFBBBRLR +FBBBBFBRLL +BFBBBBFLLR +BFFBFBBRRR +BFBFFBBLRL +FFFBBFBRLR +FFBBBBFLLL +BFBFBBFLLR +BBFBBBFRLR +BFFBBBBRLL +FFBFFFBLRL +FBFFBBFRLL +BFBBFFFLLR +FBFBBFFLRL +FFFBBBFLRR +BBFBBFFLRR +BFBBFBFLLR +BFFBFBFRRR +BFBBFFFRLR +BFFBFBBLRR +FBFBBBBLLL +FBFBFFFLRL +FFBFBBBRLL +FFBFBBBLRR +BFFBFBFLLL +FBBFFBBRRR +FBFBFBFLRR +FBBFBBBRRL +BFFBBBBRLR +FFFBFFBRRR +BFFFFBFRRR +FBBFBFFRLL +FFBBFBFRLL +BBFFBBBRLR +FFBBFFBRLL +FBBBBFFRLR +FBBFFBFLLR +BFFBFBFRLR +BBFBBBBRLL +BFBFFBBLLR +FFBFFFFRLL +BFBFFFFLRR +BBFFBFBLLL +BBFFBBBRLL +BBFBBBFLRL +FBFFBBFLRL +FBFBFBBRRR +FFBBFBFLLR +FBFFFBBRRL +BBFFBFBRRL +FBFBBFFRLR +FFBFFBBLLR +BFB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FBFBFFFLLL +BFBFBFFRLL +FBFBBFFRRL +FBBBBBBLLR +BFBFBFFRRR +FBFFBBBLRR +FBFFBFFRLR +FBFBBBBLRR +BBFFBFBLRL +FBBFBFFRLR +FBBFFFBLRR +BFBFBFFRRL diff --git a/2020/05/solution1.js b/2020/05/solution1.js new file mode 100644 index 0000000..dc48242 --- /dev/null +++ b/2020/05/solution1.js @@ -0,0 +1,29 @@ +const { readInput } = require("./util"); + +const { lines } = readInput(); + +function binToInt(binString, oneChar = "1") { + const binArr = Array.from(binString).reverse(); + let num = 0; + for (let i = 0; i < binArr.length; i++) { + if (binArr[i] === oneChar) { + num += 2 ** i; + } + } + return num; +} + +function seatId(pass) { + const row = binToInt(pass.slice(0, 7), "B"); + const col = binToInt(pass.slice(7, 11), "R"); + return row * 8 + col; +} + +for (const line of lines.slice(0, 10)) { + console.log(line, seatId(line)); +} + +const seatIds = lines.map(seatId); +console.log(seatIds); + +console.log(Math.max(...seatIds)); diff --git a/2020/05/solution2.js b/2020/05/solution2.js new file mode 100644 index 0000000..264ebc3 --- /dev/null +++ b/2020/05/solution2.js @@ -0,0 +1,31 @@ +const { readInput } = require("./util"); + +const { lines } = readInput(); + +function binToInt(binString, oneChar = "1") { + const binArr = Array.from(binString).reverse(); + let num = 0; + for (let i = 0; i < binArr.length; i++) { + if (binArr[i] === oneChar) { + num += 2 ** i; + } + } + return num; +} + +function seatId(pass) { + const row = binToInt(pass.slice(0, 7), "B"); + const col = binToInt(pass.slice(7, 11), "R"); + return row * 8 + col; +} + +const seatIds = new Set(lines.map(seatId)); + +const maxSeatId = seatId("BBBBBBBRRR"); +console.log(maxSeatId); + +for (let i = 0; i <= maxSeatId; i++) { + if (!seatIds.has(i) && seatIds.has(i - 1) && seatIds.has(i + 1)) { + console.log(i); + } +} diff --git a/2020/05/util.js b/2020/05/util.js new file mode 100644 index 0000000..3da0de2 --- /dev/null +++ b/2020/05/util.js @@ -0,0 +1,37 @@ +const fs = require("fs"); + +exports.readInput = function (filename = "input") { + const input = fs.readFileSync(filename, "utf-8").trim(); + const lines = input.split("\n"); + + let colLength = lines[0].length; + let colConsistentcy = true; + for (const line of lines) { + if (colLength != line.length) { + colConsistentcy = false; + } + } + + const avgLength = sum(lines.map((l) => l.length)) / lines.length; + + console.log("Number of lines:", lines.length); + console.log("Col-length is consistent:", colConsistentcy); + console.log("Average col-length", avgLength); + + console.log("Sample:"); + for (const line of lines.slice(0, 5)) { + console.log(line); + } + console.log("..."); + for (const line of lines.slice(lines.length - 5, lines.length)) { + console.log(line); + } + console.log("=".repeat(process.stdout.columns)); + + return { + raw: input, + lines: lines, + }; +}; + +const sum = (arr) => arr.reduce((a, b) => a + b, 0);