diff --git a/2020/day5/day5.js b/2020/day5/day5.js new file mode 100755 index 0000000..fcb8fd7 --- /dev/null +++ b/2020/day5/day5.js @@ -0,0 +1,24 @@ +#!/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; + } + } +});