Skip to content

Instantly share code, notes, and snippets.

@foxbunny
Last active February 23, 2017 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foxbunny/f088c5b8147dcea64849df9c9951bf21 to your computer and use it in GitHub Desktop.
Save foxbunny/f088c5b8147dcea64849df9c9951bf21 to your computer and use it in GitHub Desktop.
-module(fib).
-export([fib/1, tests/0]).
fibOf(0) ->
0;
fibOf(1) ->
1;
fibOf(N) ->
fibOf(N-1) + fibOf(N-2).
fib(Count, Count, Seq) ->
Seq++[fibOf(Count)];
fib(Count, Current, Seq) ->
fib(Count, Current+1, Seq++[fibOf(Current)]).
fib(Count) ->
fib(Count, 0, []).
tests() ->
[0] = fib(0),
[0, 1] = fib(1),
[0, 1, 1] = fib(2),
[0, 1, 1, 2] = fib(3),
[0, 1, 1, 2, 3] = fib(4),
pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment