Skip to content

Instantly share code, notes, and snippets.

@stavinsky
Created August 27, 2016 09:52
Show Gist options
  • Save stavinsky/672e8488d9695af1be8429f4d5784304 to your computer and use it in GitHub Desktop.
Save stavinsky/672e8488d9695af1be8429f4d5784304 to your computer and use it in GitHub Desktop.
Hackerrank erlang input and print list example
-module(solution).
-export([main/0]).
input(row) ->
input([], row);
input(column) ->
input([], column).
input(List, row)->
case io:get_line("") of
eof -> List;
Data ->
ToInteger = fun(Item) -> {Int, _} = string:to_integer(Item),
Int end,
StringList = string:tokens(Data, " "),
lists:map(ToInteger, StringList)
end;
input(List, column) when is_list(List) ->
case io:fread("", "~d") of
eof -> List;
{ok, [Item]}-> input(List++[Item], column)
end.
print(List) when is_list(List) ->
Printer = fun(Item) -> io:format("~p~n", [Item]) end,
lists:map(Printer, List).
main() ->
List = input(row),
print(List).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment