Skip to content

Instantly share code, notes, and snippets.

@jakedobkin
Created December 7, 2011 02:39
Show Gist options
  • Select an option

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

Select an option

Save jakedobkin/1441186 to your computer and use it in GitHub Desktop.
Euler 42 in JS
#!/usr/local/bin/node
// first, prep prime seive up to 7654321, which is the largest pan that doesn't fail the
// summing divisibility rules for 3 or 9
n=7654321;
myPrimes = new Array();
for (i=2;i<=n;i++)
{
myPrimes[i]=true;
}
for (i=2;i<=n;i++)
{
if (myPrimes[i])
{
for (j=2*i;j<=n;j+=i)
{
myPrimes[j]=false;
}
}
}
// then count down from 7654321
i=7654321;
found = false;
while (found == false)
{
if (myPrimes[i])
{
string = i.toString();
l = new Array();
for (j=0;j<string.length;j++)
{
l[j] = string.slice(j,(j+1));
l.sort();
if (l[0]=="1" && l[1]=="2" && l[2]=="3" && l[3]=="4" && l[4]=="5" && l[5]=="6" && l[6]=="7")
{
console.log(string);
found = true;
}
}
}
i--;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment