Created
July 24, 2016 11:47
-
-
Save vankasteelj/b6b0b30a57a46a925d8ea3b4472581b7 to your computer and use it in GitHub Desktop.
find the multiplicative persistence of a number
This file contains hidden or 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
// EN:calculate a given number's multiplicative persistence | |
// FR:calculer la persistance multiplicative d'un nombre donné | |
// Start number | nombre de départ | |
var n = 277777788888899; | |
var y = n; | |
var pst = 0; | |
while (y >= 10 && isFinite(y)) { | |
var z = 1; | |
var x = y.toString(); | |
for (var i in x) { | |
if (typeof x[i] != "function") { | |
z *= x[i]; | |
} | |
} | |
console.log(z); | |
y = z; | |
pst++; | |
} | |
console.log('%d: %d', n,pst); |
Author
vankasteelj
commented
Jul 24, 2016
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment