Last active
June 29, 2016 05:20
-
-
Save rstacruz/0720c0b3533cb658dc1ba55b86299327 to your computer and use it in GitHub Desktop.
This file contains 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
defmodule Summer do | |
def sum_of_threes_and_fives(n) when n <= 0 do | |
0 | |
end | |
def sum_of_threes_and_fives(n) when rem(n, 5) == 0 or rem(n, 3) == 0 do | |
n + sum_of_threes_and_fives(n - 1) | |
end | |
def sum_of_threes_and_fives(n) do | |
sum_of_threes_and_fives(n - 1) | |
end | |
end | |
defmodule HelloTest do | |
use ExUnit.Case | |
test "the truth" do | |
assert Summer.sum_of_threes_and_fives(3) == 3 | |
assert Summer.sum_of_threes_and_fives(5) == 8 | |
assert Summer.sum_of_threes_and_fives(20) == 98 | |
assert Summer.sum_of_threes_and_fives(999) == 233168 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment