Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@linkin-park
Created August 31, 2017 17:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linkin-park/6bfbdad80f014ef3d53d6e03f69784dc to your computer and use it in GitHub Desktop.
Save linkin-park/6bfbdad80f014ef3d53d6e03f69784dc to your computer and use it in GitHub Desktop.
-module(solution).
-export([main/0]).
%R-Repeat,L-actual List ,
main() ->
[R|L] = read_input([]),
foo(R,L).
foo(_,[]) -> [];
foo(R,[X|Xs]) -> repeat(X,R), foo(R,Xs).
repeat(_,0)->[];
repeat(X,R)-> io:format("~p~n",[X]),repeat(X,R-1).
read_input(Inp)->
case io:fread("","~d") of
eof-> reverse_list(Inp,[]);
{ok,[X]} -> read_input([X|Inp]);
_->read_input(Inp)
end .
reverse_list([],NL)->NL;
reverse_list([X|Xs],NL)->reverse_list(Xs,[X|NL]).
@kadoban
Copy link

kadoban commented Aug 31, 2017

main = interact (unlines . map show . (\(n:xs) -> f n xs) . map read . words)

would be my version of doing the input in haskell. They have something else. Most of it is boilerplate that I have written a bit differently so I don't have to mess with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment