Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re^3: e

by mtve (Deacon)
on Jul 17, 2004 at 09:36 UTC ( #375216=note: print w/replies, xml ) Need Help??

in reply to Re^2: e
in thread e

Simple optimizations down to 86:

sub e{ #234567890123456789012345678901234567890123456789012 map{$e[$q-1]+=$e[$q]/$q,($e[$q]%=$q--).=0for 1..($q=@e);$e[0]=!print"@e"|0}@e=(1)x pop } e(1000);

Update from tybalt89 - 80 chars:

$=[!print$=]=!map{$==$=[$#z]+=$=[@z]/@z,($=[@z]%=1+$#z--).=0}@z=@=for@ +==(1)x pop

Replies are listed 'Best First'.
Re^4: e
by shmem (Chancellor) on Sep 13, 2015 at 09:47 UTC
    $=[!print$=]=!map{$==$=[$#z]+=$=[@z]/@z,($=[@z]%=1+$#z--).=0}@z=@=for@ +==(1)x pop

    Segfaults with perl v5.18.2:

    qwurx [shmem] ~> perl -e '$=[!print$=]=!map{$==$=[$#z]+=$=[@z]/@z,($=[ +@z]%=1+$#z--).=0}@z=@=for@==(1)x pop' 10 Attempt to free unreferenced scalar: SV 0xdd0968, Perl interpreter: 0x +da4010 at -e line 1. Segmentation fault

    Works with v5.10.1 though. Looks like the segfault happens here:


    Can't (for now) figure out why.

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
Re^4: e
by tachyon (Chancellor) on Jul 17, 2004 at 10:02 UTC

    There was a bug in the code I posted. AFAIK it does not effect the result per se just the efficiency. By trying to scrape a char by using @e instead of $#e (as used in IOs code) within the inner loop we are accessing a non existent element one past the end of the array. As a result @e is growing by one with each inner loop.



Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://375216]
[Perl300]: Hi all
[Perl300]: I have a quick question about the Meta CPAN
[Perl300]: On any modules pod page, what does the date on top left corner below authors name indicate?

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2017-12-11 17:53 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (310 votes). Check out past polls.