Created
August 27, 2016 09:52
-
-
Save stavinsky/672e8488d9695af1be8429f4d5784304 to your computer and use it in GitHub Desktop.
Hackerrank erlang input and print list example
This file contains 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
-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