Skip to content

Instantly share code, notes, and snippets.

@jakedobkin
Created December 7, 2011 00:19
Show Gist options
  • Select an option

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

Select an option

Save jakedobkin/1440758 to your computer and use it in GitHub Desktop.
Project Euler 40 in JS
#!/usr/local/bin/node
// calculate the decimal to 1MM places, but record certain values
string = "";
for (i=1;i<=1000000;i++)
{
string += i.toString()
}
d1 = Number(string.slice(0,1));
d10 = Number(string.slice(9,10));
d100 = Number(string.slice(99,100));
d1000 = Number(string.slice(999,1000));
d10000 = Number(string.slice(9999,10000));
d100000 = Number(string.slice(99999,100000));
d1000000 = Number(string.slice(999999,1000000));
sum = d1 * d10 * d100 * d1000 * d10000 * d100000 * d1000000;
console.log(sum);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment