Part 1 JS solution, (maybe) Part 2 coming soon (This Chinese remainder theorem thing sounds complicated for a 7th grader and looking at other comments brute force for part 2 doesn't seem like an option)
const fs = require("fs"); let data = fs.readFileSync("input.txt", "utf8").split("\n") let num = Number(data[0]); let busnumbers = data[1].split(",").filter(e => e != "x").map(e => Number(e)); const dospecial = i => { let specialnum = busnumbers.map(e => { if (((num + i) % e) == 0) { return e * ((num + i) - num); } }).filter(e => e) return specialnum; } for (let i = 0; true; i++) { let specialnum = dospecial(i) if (specialnum.length) { console.log(specialnum[0]) break; } }
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, (maybe) Part 2 coming soon (This Chinese remainder theorem thing sounds complicated for a 7th grader and looking at other comments brute force for part 2 doesn't seem like an option)