Skip to content

Instantly share code, notes, and snippets.

@felipe-araujo
Created March 12, 2020 14:50
Show Gist options
  • Save felipe-araujo/c41ede9d15a6ca25c1a2f394f1feab85 to your computer and use it in GitHub Desktop.
Save felipe-araujo/c41ede9d15a6ca25c1a2f394f1feab85 to your computer and use it in GitHub Desktop.
Read from stdio until reach EOF in Elixir(for HackerRank)
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