Perl: the Markov chain saw PerlMonks

### e

by tachyon (Chancellor)
 on Jul 16, 2004 at 08:19 UTC Need Help??

```sub e {
\$N=pop;\$a[\$_]=int(1+1/\$_)for 1..\$N;for(;\$N>9;print int\$x)
{for(\$n=\$N--;--\$n;\$a[\$n]=\$x%\$n,\$x=10*\$a[\$n-1]+\$x/\$n){}}
}
e(1000);
[download]```

NB: Based on work by Xavier Gourdon e

cheers

tachyon

Replies are listed 'Best First'.
Re: e
by Discipulus (Monsignor) on Jul 16, 2004 at 10:37 UTC
good morning wise one

A part obfu that for me is very obfuscated what you are printing out ?? a suit of numbers gorwing up of a char as the argoument is > 10.
the sequence have every time the same beginning without evident internal repetitions until the argoument is < 10000 ... which kind of number is ??
which kind of number is ??

It's e

He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

Chady | http://chady.net/
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE!!!
```perl -e 'print exp 1'
[download]```
• perldoc -f exp
• perldoc -f log
NOW I KNOW WHY I 'M GRADUATED IN MEDIAVAL HISTORY !!

cheers lorenzo*
Re: e
by I0 (Priest) on Jul 17, 2004 at 06:04 UTC
```sub e{
use integer;
my @e=(1) x shift;
for(1..@e*log(@e)/3){
for(reverse(1..\$#e)){
\$e[\$_-1]+=\$e[\$_]/\$_; \$e[\$_]%=\$_;
}
printf"%01d",\$e[0]; \$e[0]=0;
\$_*=10 for @e;
}
}
[download]```

Cool. Lovely piece of code.

Map gets it down to 105 chars - yes void maps are good for golf only!

```sub e{
#234567890123456789012345678901234567890123456789012
@e=(1)x pop;map{map{\$e[\$_-1]+=\$e[\$_]/\$_;\$e[\$_]=10*(\$
e[\$_]%\$_)}reverse 1..\$#e;print int\$e[0];\$e[0]=0}1..@e
}

# or if you prefer whitespace and no void maps
sub e{
@e=(1)x pop;
for(1..@e){
for(reverse(1..\$#e)){
\$e[\$_-1]+=\$e[\$_]/\$_;
\$e[\$_]=10*(\$e[\$_]%\$_)
}
print int \$e[0];
\$e[0]=0
}
}
[download]```

cheers

tachyon

Re^3: e
by mtve (Deacon) on Jul 17, 2004 at 09:36 UTC

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);
[download]```

Update from tybalt89 - 80 chars:

```\$=[!print\$=]=!map{\$==\$=[\$#z]+=\$=[@z]/@z,(\$=[@z]%=1+\$#z--).=0}@z=@=for@
+==(1)x pop
[download]```
Re^4: e
by shmem (Chancellor) on Sep 13, 2015 at 09:47 UTC
Re: e
by Anonymous Monk on Jul 18, 2004 at 02:43 UTC
You're missing a period :)
Re^2: e
by I0 (Priest) on Jul 18, 2004 at 08:21 UTC
```sub e{
my @e=(1)x shift;
my \$f="%d.";
local \$|=1;
for(1..@e*log(@e)/11){
for(reverse(1..\$#e)){
\$e[\$_-1]+=\$e[\$_]/\$_;
\$e[\$_]=10000*(\$e[\$_]%\$_)
}
printf\$f,\$e[0];
\$e[0]=0;
\$f="%04d";
}
}
[download]```

Log In?
 Username: Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://374942]
Approved by Corion
Front-paged by injunjoel
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2018-04-22 05:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
My travels bear the most uncanny semblance to ...

Results (82 votes). Check out past polls.

Notices?