Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

20
  • \$\begingroup\$ Great idea using primes. \$\endgroup\$ Commented Mar 8, 2011 at 16:06
  • 2
    \$\begingroup\$ You can shave a couple of characters off the dictionary initialisation using the sieve. a=[2];for(p=3,j=0;j<26;)if(a[j]){if(p%a[j++]==0){p++;j=0}}else{a[j]=p;j=0} \$\endgroup\$ Commented Mar 8, 2011 at 17:06
  • \$\begingroup\$ I feel like I read about this trick on some blog talking about interview questions... \$\endgroup\$ Commented Mar 9, 2011 at 3:06
  • 1
    \$\begingroup\$ @Tom, depends on how well optimised the sorting routines are, given that you've limited inputs to 8 characters :P \$\endgroup\$ Commented Mar 9, 2011 at 11:13
  • 1
    \$\begingroup\$ 125 characters. Recursion and ternaries FTW: for(a=[j=p=2];j<123;)a[j]?p%a[++j]<1&&p++&&(j=0):(a[j]=p,j=0);function b(c,i){return c[i=i||0]?a[c.charCodeAt(i)]*b(c,++i):1} \$\endgroup\$ Commented Mar 9, 2011 at 14:03