Skip to content

Instantly share code, notes, and snippets.

@jakedobkin
Created December 5, 2011 01:00
Show Gist options
  • Select an option

  • Save jakedobkin/1431857 to your computer and use it in GitHub Desktop.

Select an option

Save jakedobkin/1431857 to your computer and use it in GitHub Desktop.
Euler 34
#!/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