Part 1 JS solution, I've been hearing that Part 2 day 16 is a very hard part 😳, hope I'll be able to finish that
const fs = require("fs") let data = fs.readFileSync("input.txt","utf8"), rules = data.match(/(.|\n)+(?=\n\syour ticket:)/i)[0].split("\n"), valids = new Set(); rules.forEach(e => { e.match(/\d+-\d+/gi).forEach(e => { for (let i = Number(e.match(/\d+/i));i <= Number(e.match(/(?<=\d+-)\d+/)[0]);i++) { valids.add(i) } }) }) let nearbytickets = data.match(/(?<=ts:\n)(.|\n)+/)[0].split("\n"); let invalids = []; for (let i = 0,n=nearbytickets.length;i < n; i++) { let theticket = nearbytickets[i].split(",").map(e=>Number(e)); for (let j = 0,o=theticket.length; j < o; j++) { let isvalid = valids.has(theticket[j]); if (!isvalid) invalids.push(theticket[j]) } } if (invalids.length) console.log(invalids.reduce((a,e) => a+e)) else console.log(0)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Part 1 JS solution, I've been hearing that Part 2 day 16 is a very hard part
😳, hope I'll be able to finish that