Created
February 14, 2019 16:14
-
-
Save ck3g/faa5df7c9b380430c5a192115806f341 to your computer and use it in GitHub Desktop.
How to read from STDIN 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 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 |
TB-Development
commented
Nov 9, 2021
•
https://gist.github.com/uxjp/e8e73a121f2d6563718db58eb3332c3a
Here is different solution, not using pipes all the way. I'm just beggining with Elixir, will I do everything with pipes in the future ?
Here is different solution, not using pipes all the way. I'm just beggining with Elixir, will I do everything with pipes in the future ?
FWIW you don't have to use the pipe operator |>
at all, but it is seen as somewhat idiomatic in Elixir. See: https://elixirschool.com/en/lessons/basics/pipe_operator
FWIW
Thanks for the advice Simon.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment