Skip to content

Instantly share code, notes, and snippets.

@kheniparth
Created January 27, 2018 21:38
Show Gist options
  • Save kheniparth/93b21e2b0482ef7b5e01e93ae3a9f3ea to your computer and use it in GitHub Desktop.
Save kheniparth/93b21e2b0482ef7b5e01e93ae3a9f3ea to your computer and use it in GitHub Desktop.
AND operator with cond in Elixir
#Given an integer, , perform the following conditional actions:
#If is odd, print Weird
#If is even and in the inclusive range of to , print Not Weird
#If is even and in the inclusive range of to , print Weird
#If is even and greater than , print Not Weird
#Complete the stub code provided in your editor to print whether or not is weird.
defmodule Solution do
#Enter your code here. Read input from STDIN. Print output to STDOUT
import Integer
{number, _} = String.trim(IO.gets "") |> Integer.parse
cond do
number in 2..5 and is_even(number) -> IO.puts "Not Weird"
number in 6..20 and is_even(number) -> IO.puts "Weird"
number > 20 and is_even(number) -> IO.puts "Not Weird"
is_odd(number) -> IO.puts "Weird"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment