25 lines
628 B
JavaScript
25 lines
628 B
JavaScript
|
#!/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;
|
||
|
}
|
||
|
}
|
||
|
});
|