Even Odd in Elixir

Published on 03 October 2020 (Updated: 04 October 2020)

Welcome to the Even Odd in Elixir page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

defmodule EvenOdd do
    require Integer

    @doc """
    Determine whether a supplied number is Even or Odd.
    Return an error-string if the argument is missing or invalid. 
    @spec main(argv :: list( String.t())) :: String.t()
    def main(argv) do
        if length(argv) != 1 do
            "Usage: please input a number"
            case argv |> List.first |> Integer.parse do
                {number, ""} -> even_odd_string(number)
                {_, _rest} -> "Usage: please input a number"
                :error -> "Usage: please input a number"

    @spec even_odd_string(number :: integer) :: String.t()
    defp even_odd_string(number) do
        case Integer.is_even(number) do
            true -> "Even"
            false -> "Odd"

EvenOdd.main(System.argv()) |> IO.puts

Even Odd in Elixir was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.