Created
May 28, 2020 16:19
-
-
Save beothorn/84fd7d4ae92c44c1b52a59055253f42f to your computer and use it in GitHub Desktop.
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 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is https://en.wikipedia.org/wiki/Look-and-say_sequence