Last active
June 29, 2016 04:07
-
-
Save rstacruz/1a103b94224574513ad9fd07d7305772 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) do | |
0..n | |
|> Stream.filter(&multiple_of_3_or_5?/1) | |
|> Enum.reduce(&Kernel.+/2) | |
end | |
def multiple_of_3_or_5?(n) do | |
rem(n, 5) == 0 || rem(n, 3) == 0 | |
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