Created
January 27, 2018 21:38
-
-
Save kheniparth/93b21e2b0482ef7b5e01e93ae3a9f3ea to your computer and use it in GitHub Desktop.
AND operator with cond in Elixir
This file contains hidden or 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
#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