Last active
December 3, 2017 19:55
-
-
Save Falci/86a4888072568c1faacaf54adcc7f2ed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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