advent-of-code/2020/day5/day5.js

25 lines
628 B
JavaScript
Raw Normal View History

2020-12-05 13:39:12 +01:00
#!/bin/node
const fs = require('fs');
fs.readFile('input.txt', (err, data) => {
const seats = data.toString()
.split('\n')
.filter(l => l.length > 0)
.map(s => s.replaceAll(/[BR]/g, '1')
.replaceAll(/[FL]/g, '0'))
.map(s => parseInt(s, 2));
console.log('Highest seat:', seats.reduce((a, v) => v > a ? v : a, -1));
seats.sort();
for (let i = 0; i < seats.length; i++) {
const seat = seats[i];
const nextSeat = seats[i + 1];
if (nextSeat - seat === 2) {
console.log('Your seat:', seat + 1);
break;
}
}
});