From 1a7717e25e93599666803bb11f80c87117b01114 Mon Sep 17 00:00:00 2001 From: s-lando Date: Sun, 13 Nov 2022 15:01:02 -0800 Subject: elixir fibs --- entries/s-lando/fib.ex | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 entries/s-lando/fib.ex diff --git a/entries/s-lando/fib.ex b/entries/s-lando/fib.ex new file mode 100644 index 0000000..e4783d6 --- /dev/null +++ b/entries/s-lando/fib.ex @@ -0,0 +1,19 @@ +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 -- cgit v1.2.3-70-g09d2 From 187a21d862e3f16eb995bfa64016c61ef20fd6be Mon Sep 17 00:00:00 2001 From: s-lando Date: Sun, 13 Nov 2022 15:11:04 -0800 Subject: added to people.json --- people.json | 11 +++++++++++ 1 file changed, 11 insertions(+) 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" + } + ] } ] -- cgit v1.2.3-70-g09d2 From 75a7ff9378a90324d587bd37dd0861a52bdf0414 Mon Sep 17 00:00:00 2001 From: s-lando Date: Sun, 13 Nov 2022 15:16:12 -0800 Subject: newline formatting --- entries/s-lando/fib.ex | 1 + 1 file changed, 1 insertion(+) diff --git a/entries/s-lando/fib.ex b/entries/s-lando/fib.ex index e4783d6..fae4d3c 100644 --- a/entries/s-lando/fib.ex +++ b/entries/s-lando/fib.ex @@ -16,4 +16,5 @@ defmodule Fib do true -> fib2(n - 1, next, current + next) end end + end -- cgit v1.2.3-70-g09d2