Skip to content

Instantly share code, notes, and snippets.

@shankardevy
Created October 25, 2016 16:08
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 shankardevy/5e365a3bd6a62379abe5a1e0e69b2bd6 to your computer and use it in GitHub Desktop.
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.
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