Skip to content

Instantly share code, notes, and snippets.

@rstacruz
Last active June 29, 2016 04:07
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/1a103b94224574513ad9fd07d7305772 to your computer and use it in GitHub Desktop.
Save rstacruz/1a103b94224574513ad9fd07d7305772 to your computer and use it in GitHub Desktop.
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