-
-
Save yrashk/aafded15a61bc081fcd1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fib_list(0) -> 0; | |
fib_list(1) -> 1; | |
fib_list(N) -> | |
fib_list(N + 1, [1,0]). | |
fib_list(End, [H|_]=L) when length(L) == End -> H; | |
fib_list(End, [A,B|_]=L) -> | |
fib_list(End, [A+B|L]). |
I agree
Either way, the point was to show one person how lists are constructed
Right.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ouch! Don't use length(L) in a loop! It has to traverse the list L to count the elements each time. You could use a separate accumulator variable N to keep track of the length of L.