We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
2023 / 10 / 11
TIL: Read from STDIN in Elixir on HackerRank
2023 / 10 / 11
Grab input data in HackerRank problems
elixir
Grab the input provided by HackerRank from STDIN with:
input = IO.read(:stdio, :all)
|> String.split("\n", trim: true)
If the input provided are numbers you might want to chain the above with:
input = IO.read(:stdio, :all)
|> String.split("\n", trim: true)
|> Enum.map(&String.to_integer/1)
In recent versions of Elixir (v1.13.0 or above) you might
want to use IO.read(:stdio, :eof)
instead.
But HackerRank is running Elixir 1.8.2 which don’t
support the :eof
option yet (LeetCode uses 1.15.7 by
the way…).
You can look at the Elixir version from within the REPL
with: System.version
.