Created
August 31, 2017 17:51
-
-
Save linkin-park/6bfbdad80f014ef3d53d6e03f69784dc to your computer and use it in GitHub Desktop.
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]). | |
%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]). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.