Created
October 25, 2016 16:08
-
-
Save shankardevy/5e365a3bd6a62379abe5a1e0e69b2bd6 to your computer and use it in GitHub Desktop.
A program that prints out the numbers 1 to 100 (inclusive). If the number is divisible by 3, print Crackle instead of the number. If it's divisible by 5, print Pop. If it's divisible by both 3 and 5, print CracklePop.
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 Math do | |
def map_number(number) do | |
case { rem(number,3), rem(number,5) } do | |
{ 0, 0 } -> | |
"CradlePop" | |
{ 0, _ } -> | |
"Cradle" | |
{ _, 0 } -> | |
"Pop" | |
{ _, _ } -> | |
number | |
end | |
end | |
end | |
1..100 |> Enum.map(&Math.map_number/1) |> Enum.each(&IO.puts/1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment