Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #54108

Rosetta Code: Fibonacci n-step number sequences

From "Robert L." <No_spamming@noWhere_7073.org>
Newsgroups comp.lang.forth
Subject Rosetta Code: Fibonacci n-step number sequences
Date 2017-01-18 09:09 +0000
Organization Aioe.org NNTP Server
Message-ID <o5nbcn$u4i$1@gioia.aioe.org> (permalink)

Show all headers | View raw


> Task
> 
> Write a function to generate Fibonacci n-step number
> sequences given its initial values and assuming the number of
> initial values determines how many previous values are summed
> to make the next number of the series.
> 
> Use this to print and show here at least the first ten members
> of the Fibo/tribo/tetra-nacci and Lucas sequences.

Ruby:

def n_fib( *initial )
  Enumerator.new {|y|
    seed = initial.dup
    loop {y.yield seed[0]
      seed.push seed.reduce(:+)
      seed.shift}
  }
end

x = n_fib(1,1)
    ==>#<Enumerator: #<Enumerator::Generator:0x1639ad0>:each>
x.take 9
    ==>[1, 1, 2, 3, 5, 8, 13, 21, 34]

x = n_fib(1,1,2)
    ==>#<Enumerator: #<Enumerator::Generator:0x164d8d0>:each>
x.take 5
    ==>[1, 1, 2, 4, 7]
x.take 8
    ==>[1, 1, 2, 4, 7, 13, 24, 44]


In Forth?


-- 
One of [the Zionists'] streams of output ... tells everyone else they should
mix together ...; and the other stream of output is ... for internal
consumption, and that says an entirely different and much more healthy thing:
that Jews should intermarry with other Jews....
--- Mark Collett (archive.org/details/Duke.20161104)

Back to comp.lang.forth | Previous | Next | Find similar | Unroll thread


Thread

Rosetta Code: Fibonacci n-step number sequences "Robert L." <No_spamming@noWhere_7073.org> - 2017-01-18 09:09 +0000

csiph-web