Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

List of fibonaccie numbers

121 views
Skip to first unread message

WJ

unread,
Feb 19, 2016, 12:31:06 PM2/19/16
to
Return a list or array of the first n fibonacci numbers.

Here's an attempt in Ruby; let's see some concise
ANS Forth solutions.

def fib n
a,b=0,1
n.times.map{a,b=b,a+b; a}
end

fib 9
==>[1, 1, 2, 3, 5, 8, 13, 21, 34]

--
This is war, and our greatest enemy is the enemy within: the submissive,
apologetic, guilt-ridden, self-hating drone. The moment we manage to destroy
the enemy within, destroying the rest of our enemies will be a walk in the
park. http://www.kolumbus.fi/aquilon/londonspeech12.htm

Chris Curl

unread,
Feb 19, 2016, 1:00:33 PM2/19/16
to
: fib 0 1 rot 0 do dup . 2dup + rot drop loop 2drop ;
9 fib 1 1 2 3 5 8 13 21 34 ok

rickman

unread,
Feb 19, 2016, 2:10:34 PM2/19/16
to
Slightly more efficient perhaps.

: fib 1 0 rot 0 do over + swap dup . loop 2drop ;

--

Rick

Albert van der Horst

unread,
Feb 19, 2016, 3:01:34 PM2/19/16
to
"WJ" <w_a_...@yahoo.com> writes:

>Return a list or array of the first n fibonacci numbers.

>Here's an attempt in Ruby; let's see some concise
>ANS Forth solutions.

>def fib n
> a,b=0,1
> n.times.map{a,b=b,a+b; a}
>end

>fib 9
> ==>[1, 1, 2, 3, 5, 8, 13, 21, 34]

Oh no! Not the Fibonacci numbers again!

Groetjes Albert
--
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

novembe...@gmail.com

unread,
Feb 19, 2016, 4:53:28 PM2/19/16
to
I dont know ruby but if a & b are defined as 0, 1 shouldnt the first two entries in your array start 0 , 1 ?

NN

humptydumpty

unread,
Feb 19, 2016, 5:51:53 PM2/19/16
to
Hi, could you solve that equation for unknown definition 'X' :-) ?

\ --- excerpt from gforth command line

: boot dup execute ; redefined boot ok
\ : X left for WJ to solve ;
0 1 9 :noname X dup . tuck + ; cr boot 2drop
1 1 2 3 5 8 13 21 34 ok
.s <0> ok

\ --- end of riddle

Enjoying Forth,
humptydumpty

Paul Rubin

unread,
Feb 19, 2016, 8:19:14 PM2/19/16
to
novembe...@gmail.com writes:
> I dont know ruby but if a & b are defined as 0, 1 shouldnt the first
> two entries in your array start 0 , 1 ?

My favorite video about Ruby (and Javascript):

https://www.youtube.com/watch?v=20BySC_6HyY

WJ

unread,
Jun 27, 2016, 11:33:35 PM6/27/16
to
WJ wrote:

> Return a list or array of the first n fibonacci numbers.
>
> Here's an attempt in Ruby; let's see some concise
> ANS Forth solutions.
>
> def fib n
> a,b=0,1
> n.times.map{a,b=b,a+b; a}
> end
>
> fib 9
> ==>[1, 1, 2, 3, 5, 8, 13, 21, 34]

OCaml:

let fib n =
let rec loop a b = function
0 -> []
| i -> b :: loop b (a+b) (i-1)
in loop 0 1 n ;;

fib 9;;
===>
[1; 1; 2; 3; 5; 8; 13; 21; 34]

--
[T]he broadcast media ... create a separate and caustic virtual reality, then
broadcast that ideologically driven reality into the homes of millions of
people.... theoccidentalobserver.net/authors/Connelly-Gaza2.html

Brad Eckert

unread,
Jun 28, 2016, 3:06:02 PM6/28/16
to
On Monday, June 27, 2016 at 8:33:35 PM UTC-7, WJ wrote:
> fib 9;;
> ===>
> [1; 1; 2; 3; 5; 8; 13; 21; 34]
>
The coding of the universe can play out in funny ways:
http://lolworthy.com/funny/trump-fibonacci-spiral-golden-ratio-meme/
0 new messages