r/tinycode • u/mus1Kk • Jan 29 '16
[Perl6] Fibonacci sequence in 11 bytes
Seeing the Haskell post I thought I upped the ante.
0,1,*+*...*
Of course you can use a 1 as the first digit if you so desire.
... is the sequence operator and creates a lazy list from 0 to infinity (the last asterisk). The third element *+* is a generator. An expression with an asterisk (called Whatever) for a term is automatically made into a closure and each asterisk is assigned successively an argument. The two arguments are the two previous elements of the sequence.
Retrieving the elements is a simple list operation:
(0,1,*+*...*)[5] # 6th element
(0,1,*+*...*)[5..10] # elements 6 through 10
edit: To elaborate a bit regarding the rules. This is normal code. In fact, it's even mentioned in the documentation. There is nothing that would qualify as magic or code golfing. Every operator is used as designed. The terseness of this particular example is just a happy coincidence.
View all comments
Show parent comment
3
u/raiph Jan 29 '16
It's slightly larger (where 'slightly' is slightly understated).
Iirc the fixed executable whole program overhead (for something like
perl6 -e 'say 1') when using the Rakudo compiler front end with MoarVM as the backend (the closest Perl 6 has to a "reference" setup) is around 100MB. Lead devs have an informal goal of shrinking that to around 50MB this year.The Rakudo Perl 6 compiler is also something like 10-100 times slower than the latest stable Perl 5 executable, perl 5.22.1, for most operations. I've posted an SO answer that discusses speed.