Skip to content

Instantly share code, notes, and snippets.

@beothorn
Last active May 28, 2020 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beothorn/2244cba6c73e1a641c8951e400f9d353 to your computer and use it in GitHub Desktop.
Save beothorn/2244cba6c73e1a641c8951e400f9d353 to your computer and use it in GitHub Desktop.
playing around a joke sequence
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