Skip to content

Instantly share code, notes, and snippets.

@und3f
Last active October 17, 2021 09:12
Show Gist options
  • Save und3f/cfba0e50196c466d26bb2b72883e12cc to your computer and use it in GitHub Desktop.
Save und3f/cfba0e50196c466d26bb2b72883e12cc to your computer and use it in GitHub Desktop.
AOC 2017 day 13 in-browser solutions
(function(input) {
let firewall = []
for (let wall of input.split("\n").map(r => r.split(": "))) {
firewall[parseInt(wall[0])] = parseInt(wall[1])
}
let severity = 0
for (let position = 0; position < firewall.length; position++) {
const scannerTower = firewall[position]
let scanner
if (scannerTower !== undefined)
scanner = (position + 1) % (scannerTower*2-2)
if (scanner === 1)
severity += position * scannerTower
console.log(position, scanner, severity)
}
return severity
})(document.body.textContent.trim())
(function(input) {
let firewall = []
for (let wall of input.split("\n").map(r => r.split(": "))) {
firewall[parseInt(wall[0])] = parseInt(wall[1])
}
let test = function (delay) {
let severity = 0
for (let position = 0; position < firewall.length; position++) {
const scannerTower = firewall[position]
let scanner
if (scannerTower !== undefined)
scanner = (position + 1 + delay) % (scannerTower*2-2)
if (scanner === 1) {
severity += position * scannerTower
return 1
console.log("ALARM", position, scanner)
}
// console.log(position, scanner, severity)
}
return severity
}
for (let delay = 1; ; delay += 1) {
let v = test(delay)
//console.log(delay, v)
if (v === 0)
return delay
}
})(document.body.textContent.trim())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment