Last active
May 28, 2020 15:36
-
-
Save beothorn/2244cba6c73e1a641c8951e400f9d353 to your computer and use it in GitHub Desktop.
playing around a joke sequence
This file contains 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
var next = (numberString) =>{ | |
const count = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] | |
for(c of numberString){ | |
count[parseInt(c)]++ | |
} | |
let nextString = "" | |
for(c of numberString){ | |
if(count[parseInt(c)] > 0){ | |
nextString += count[parseInt(c)] + c | |
count[parseInt(c)] = 0 | |
} | |
} | |
return nextString | |
} | |
var printSeq = (start) => { | |
let previous = start | |
console.log(previous) | |
const alreadyCounter = new Set() | |
while(!alreadyCounter.has(previous)){ | |
alreadyCounter.add(previous) | |
previous = next(previous) | |
console.log(previous) | |
} | |
console.log(previous) | |
console.log("loop "+ alreadyCounter.size) | |
} | |
var convergence = (start) => { | |
let previous = start + "" | |
let count = 0 | |
const alreadyCounter = new Set() | |
while(!alreadyCounter.has(previous)){ | |
alreadyCounter.add(previous) | |
previous = next(previous) | |
count++ | |
} | |
return [previous, count] | |
} | |
var stableIslands = new Set() | |
for(let i=0; i<=100000; i++){ | |
let conv = convergence(i) | |
str = conv[0].substring(0, conv[0].length - 1) | |
// stableIslands.add(str + "X") | |
stableIslands.add(conv[0]) | |
//console.log(i+" times:"+conv[1]+": "+conv[0]) | |
} | |
console.log(stableIslands) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment