Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: challenge: OEIS A073015 serie

by danaj (Friar)
on Dec 18, 2015 at 12:44 UTC ( [id://1150692] : note . print w/replies, xml ) Need Help??


in reply to challenge: OEIS A073015 serie

Without using a bigint module, you can't generate much of the series. I suspect correct Perl 6 solutions would be really easy.

use bigint; my $f=3; for (1..12) { $f = ($f-1)**2 if $_>1; say $f } # Faster: replace bigint with Math::GMP qw/:constant/;

I admit I find code golf to be tiresome, and prefer readable and efficient solutions.

Replies are listed 'Best First'.
Re^2: challenge: OEIS A073015 serie
by Laurent_R (Canon) on Dec 18, 2015 at 23:11 UTC
    I suspect correct Perl 6 solutions would be really easy.
    Yes, indeed, really easy in Perl 6, except that you can't seem to get to infinity. ;-) So there is a need for some other way of stopping the calculation than just looking for /inf/ or the like.

    In fact, it is so easy that I just needed to copy and paste your code and run it with Perl 6/Rakudo:

    $ perl6 -e 'my $f=3; for (1..16) { $f = ($f-1)**2 if $_>1; say $f }' 3 4 9 64 3969 15745024 247905749270529 61457260521381894004129398784 ...
    The full output for those interested with big nums (adding an extra newline between the numbers for a better clarity of output) is given below: The last number above has more than 7300 digits. The whole one-liner script executes in less than 1 second, but it starts to show a noticeable slow down when getting above 16.
Re^2: challenge: OEIS A073015 serie
by Anonymous Monk on Dec 18, 2015 at 17:10 UTC

    Trolling season!

    perl -E 'say(eval),$,.=$#$,$,x=eval,redo,for$,="+3"'