Created
March 12, 2020 14:50
-
-
Save felipe-araujo/c41ede9d15a6ca25c1a2f394f1feab85 to your computer and use it in GitHub Desktop.
Read from stdio until reach EOF in Elixir(for HackerRank)
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
defmodule Console do | |
def read_until_eof() do | |
read_until_eof([]) | |
end | |
def read_until_eof(acc) do | |
case IO.read(:stdio, :line) do | |
:eof -> | |
acc | |
data -> | |
acc = acc ++ [String.to_integer(String.trim(data))] | |
read_until_eof(acc) | |
end | |
end | |
end | |
array = Console.read_until_eof() | |
IO.inspect(array) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment