Skip to content

Instantly share code, notes, and snippets.

@ck3g
Created February 14, 2019 16:14
Show Gist options
  • Save ck3g/faa5df7c9b380430c5a192115806f341 to your computer and use it in GitHub Desktop.
Save ck3g/faa5df7c9b380430c5a192115806f341 to your computer and use it in GitHub Desktop.
How to read from STDIN in Elixir (for HackerRank)
defmodule Solution do
#Enter your code here. Read input from STDIN. Print output to STDOUT
end
array_length = IO.read(:stdio, :line)
array = IO.read(:stdio, :line)
array_length
|> String.trim
|> String.to_integer
|> IO.puts
array
|> String.split(" ")
|> Enum.map(fn n -> String.to_integer(n) end)
|> IO.inspect
@uxjp
Copy link

uxjp commented Sep 9, 2022

FWIW

Thanks for the advice Simon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment