Skip to content

Instantly share code, notes, and snippets.

@Falci
Last active December 3, 2017 19:55
Show Gist options
  • Save Falci/86a4888072568c1faacaf54adcc7f2ed to your computer and use it in GitHub Desktop.
Save Falci/86a4888072568c1faacaf54adcc7f2ed to your computer and use it in GitHub Desktop.
const code = document.getElementsByTagName('pre')[0].innerHTML.trim();
let sum = 0;
for(let i=1; i<code.length;i++) {
const current = code[i],
prev = code[i-1];
if(current === prev) { sum += parseInt(current, 10) }
}
if(code[0] === code[code.length-1]) sum += parseInt(code[0], 10)
document.getElementsByTagName('pre')[0].innerHTML = sum;
document.getElementsByTagName('pre')[0].innerHTML.trim().split('\n')
.map(line => line.split(/\D+/))
.map(line => Math.max.apply(null, line) - Math.min.apply(null, line))
.reduce((a, b) => a+b, 0)
const steps = n => {
const root = Math.ceil(Math.sqrt(n)),
curR = root % 2 !== 0 ? root : root + 1,
numR = (curR - 1) / 2,
cycle = n - ((curR - 2) ** 2),
innerOffset = cycle % (curR - 1);
return numR + Math.abs(innerOffset - numR);
};
console.log(steps(325489));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment