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); } }