Last active
          August 12, 2018 16:48 
        
      - 
      
- 
        Save H12/428ba54d1cb3a5db2bc215568368a27d to your computer and use it in GitHub Desktop. 
    Helpers for reading Hackerrank input in Elixir
  
        
  
    
      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 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