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

Re: Fibonacci numbers (again)

by ambrus (Abbot)
on Sep 09, 2005 at 12:01 UTC ( [id://490532]=note: print w/replies, xml ) Need Help??


in reply to Fibonacci numbers (again)

This is even shorter, but it prints newlines, not spaces. It's better than the perl one because it calculates all digits.

dc -e1d[pdsd+ldrlxx]dsxx
If it's enough to have the first say 40 elements of the sequence (depending on an internal limitation of dc) then this is 2 chars shorter:
dc -e1d[pdk+Krlxx]dsxx

If you insist on spaces, here's a version:

dc -e1d[ddn32Psd+ldrlxx]dsxx

These depend on the dc extension command r (and the last one on n and P too), but these are present in both GNU dc and FreeBSD dc, so it might be portable now.

Update 2006 nov 15:

This is slightly longer than the above but is still interesting:

dc -e'1[pdd5**v1++2/lxx]dsxx'

Update 2007 jul 17: some explanation in Re^3: Fibo Golf challenge on 3 monkeys.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://490532]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-25 06:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found