Skip to content

Instantly share code, notes, and snippets.

@beothorn
Created May 28, 2020 16:19
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/84fd7d4ae92c44c1b52a59055253f42f to your computer and use it in GitHub Desktop.
Save beothorn/84fd7d4ae92c44c1b52a59055253f42f to your computer and use it in GitHub Desktop.
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 greater = 0;
var greaterCount = 0;
for(let i=0; i<=100000; i++){
const rand = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)
let conv = convergence(rand)
if(conv[1] > greaterCount){
greaterCount = conv[1]
greater = rand
}
//22: 1111001981093311
}
console.log(greaterCount + " : "+ greater)
@beothorn
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment