Skip to content

Instantly share code, notes, and snippets.

@H12
Last active August 12, 2018 16:48
Show Gist options
  • Save H12/428ba54d1cb3a5db2bc215568368a27d to your computer and use it in GitHub Desktop.
Save H12/428ba54d1cb3a5db2bc215568368a27d to your computer and use it in GitHub Desktop.
Helpers for reading Hackerrank input in Elixir
defmodule Helpers do
# Reads single integer from STDIN
def read_int do
IO.gets("") |> String.trim |> String.to_integer
end
# Reads list from STDIN
def read_list do
IO.stream(:stdio, :line)
|> Enum.to_list
|> Enum.map(&String.trim/1)
end
# Reads list of integers from STDIN
def read_int_list do
read_list()
|> Enum.map(&String.to_integer/1)
end
# Writes list to the STDOUT
def write_list(list) do
Enum.each(list, fn(x) -> IO.inspect x end)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment