diff options
author | Braxton Hall | 2022-11-14 00:29:47 +0000 |
---|---|---|
committer | GitHub | 2022-11-14 00:29:47 +0000 |
commit | f8115739b6ed7c64bbfb7fcfb9d7c76812d0dbd4 (patch) | |
tree | 7dc3d42dbd0f8782d8018fa5b37a2e76cbad6cfa | |
parent | 7e8d796440aac327b911f86e6ed7502d7e095fcc (diff) | |
parent | 75a7ff9378a90324d587bd37dd0861a52bdf0414 (diff) |
Merge pull request #82 from s-lando/main
Added Elixir Fib
-rw-r--r-- | entries/s-lando/fib.ex | 20 | ||||
-rw-r--r-- | people.json | 11 |
2 files changed, 31 insertions, 0 deletions
diff --git a/entries/s-lando/fib.ex b/entries/s-lando/fib.ex new file mode 100644 index 0000000..fae4d3c --- /dev/null +++ b/entries/s-lando/fib.ex @@ -0,0 +1,20 @@ +defmodule Fib do + # elegant + def fib(n) when n < 2, do: n + def fib(n), do: fib(n - 1) + fib(n - 2) + + + # less elegant + def fib2(n) do + fib2(n, 0, 1) + end + + def fib2(n, current, next) do + cond do + n == 0 -> current + n == 1 -> next + true -> fib2(n - 1, next, current + next) + end + end + +end diff --git a/people.json b/people.json index bae371e..59f55bf 100644 --- a/people.json +++ b/people.json @@ -653,5 +653,16 @@ "link": "./entries/gerui/fib.pl" } ] + }, + { + "github": "s-lando", + "name": "Sam Lando", + "title": "BA, UBC", + "entries": [ + { + "name": "elixir", + "link": "./entries/s-lando/fib.ex" + } + ] } ] |