Created
December 5, 2011 01:00
-
-
Save jakedobkin/1431857 to your computer and use it in GitHub Desktop.
Euler 34
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
| #!/usr/local/bin/node | |
| // these are the values of the factorials of each digit from 0-9- from earlier exercise | |
| factorial = [1,1,2,6,24,120,720,5040,40320,362880] | |
| sum = 0; | |
| // you could use advanced math to figure out the upper bound- i just tried up to 10^7 | |
| for (a=3;a<=100000;a++) | |
| { | |
| total = 0; | |
| a = a.toString(); | |
| for (i=0;i<=a.length-1;i++) | |
| { | |
| digit = a.charAt(i); | |
| digit = Number(digit); | |
| digitvalue = factorial[digit]; | |
| total = total + digitvalue; | |
| } | |
| if (total==Number(a)) | |
| { | |
| console.log(a); | |
| sum = sum + Number(a); | |
| } | |
| } | |
| console.log("sum is",sum); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment