Skip to content

Commit

Permalink
Add a fib example
Browse files Browse the repository at this point in the history
  • Loading branch information
olabini committed Nov 5, 2009
1 parent 06dccbe commit 185391f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions examples/misc/lastFib.ik
@@ -0,0 +1,30 @@

FibSequence = Sequence with(
initialize: method(
@index = 0
@last1 = 1
@last2 = 1
),

next?: true,
next: method(
result = case(@index,
0, 1,
1, 1,
else, @last1 + @last2)

@index++
@last1 = @last2
@last2 = result

result
)
)

fib = method("Returns a sequence that generates all the fibonacci numbers",
FibSequence mimic
)

; find the index of the first fibonacci number larger than a thousand
(fib indexed(from: 1) takeWhile(second < 1000) last first + 1) println
fib indexed(from: 1) droppedWhile(second < 1000) first first println

0 comments on commit 185391f

Please sign in to comment.