Skip to content

Instantly share code, notes, and snippets.

@rockydd
Last active January 5, 2020 22:00
Show Gist options
  • Save rockydd/a0d5883f26569842b07d932f3cf5eeba to your computer and use it in GitHub Desktop.
Save rockydd/a0d5883f26569842b07d932f3cf5eeba to your computer and use it in GitHub Desktop.
fib_(1,[1]).
fib_(2,[1,1]).
fib_(3, [H|[A|[B|Tail]]]) :- fib_(2, [A|[B|Tail]]), H is A + B.
fib_(N, [H|[A|[B|Tail]]]) :- N2 is N - 1, fib_(N2, [A|[B|Tail]]), H is A + B.
fib(N, List) :- fib_(N, List0), reverse(List0, List).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment