Skip to content

Instantly share code, notes, and snippets.

@rstacruz
Last active June 29, 2016 05:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rstacruz/0720c0b3533cb658dc1ba55b86299327 to your computer and use it in GitHub Desktop.
Save rstacruz/0720c0b3533cb658dc1ba55b86299327 to your computer and use it in GitHub Desktop.
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