You're viewing a comment by Shlomi Fish and its responses.
You're viewing a comment by Shlomi Fish and its responses.
I am being sponsored by Syntress! They bought me an amazing dedicated server to run catonmat on. If you're looking web services, I highly recommend the Syntress guys!
I am being sponsored by A-Writer! If you ever need help with essay writing, look no further than A-Writer! They will help you with your writing in as quickly as 3 hours!
I love to read science books. They make my day and I get ideas for awesome blog posts, such as Busy Beaver, On Functors, Recursive Regular Expressions and many others.
Take a look at my
Amazon wish list, if you're curious about what I have planned reading next, and want to surprise me. :)
If you are interested in advertising on catonmat.net, contact me.
Free tools for coding on Vietstarsoft.com.
Programming homework help.


Hi Peteris!
Thanks for this post.
A few notes about your solutions:
1. Your primality check may be short but it has awful complexity:
See this post to Hackers-IL.
perl -MList::Util=sum -alne 'push @S,@F END { print sum @S }'You do realise you are constructing an incredibly large array (and arrays in Perl have a lot of memory overhead), and then summing it all at once? Furthermore you are missing a semicolon between "@F" and "END":
shlomi:~$ perl -MList::Util=sum -alne 'push @S,@F END { print sum @S }' Bareword found where operator expected at -e line 1, near "@F END" (Missing operator before END?) syntax error at -e line 1, near "@F END " syntax error at -e line 1, near ";}" Execution of -e aborted due to compilation errors.I suggest the following instead:
perl -MList::Util=sum -alne '$s += sum @F; END { print $s }'Though one should consider using a big numbers package here.
I'm posting what I have now so I'll be sure the comment will be OK. (Got no comment preview after all).
Reply To This Comment