Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Veja mais em: https://www.youtube.com/watch?v=voV5OBCqlVs
function cycleLen(n){
let steps = 1
while(n !== 1){
if ( n % 2 === 0){
n = n / 2
}else{
n = 3 * n + 1
}
steps++
}
return steps
}
function maxCycle(i,j){
let max = cycleLen(i)
for (let k = i + 1; k <= j; k++) {
let currentCycle = cycleLen(k)
if (currentCycle > max) {
max = currentCycle
}
}
return i+' '+j+' '+max
}
console.log(maxCycle(1,10))
console.log(maxCycle(100,200))
console.log(maxCycle(201,210))
console.log(maxCycle(900,1000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment