in reply to Re^2: Canadian Cryptography Contest
in thread Canadian Cryptography Contest

perl -e'map$\+=$_,/./g for 1..1e6;print'
also works. OTOH before this is done running you should be able to reason out why the answer is 27,000,001. (Big hint. The 1 is the contribution from the 7'th digit.) As for map chocking, if you are on any Perl before 5.6.1, the many for one map shows quadratic performance, so it will indeed choke and remain choked for a good while on a million entries.

Replies are listed 'Best First'.
Re^4: Canadian Cryptography Contest
by tadman (Prior) on Jan 23, 2002 at 00:37 UTC
    map choked completely, by using massive amounts of memory.
    This is perl, v5.6.1 built for i686-linux
    Must be one of those things.
      Hrm.

      Possible. After all you are taking a list of a million, turning that into a list of about 6 million things, then allocating 6 million scalars. If each scalar takes 32 bytes, that is 192 MB just for the scalars, not even counting the space taken by the stack...

      With 5.6.0 and earlier you would have had the same potential problem, but would likely get bored before taking enough hours to get there.