We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
-module(solution).-export([main/0]).%% Rotates a string N timesrotate(S,0)->S;rotate([X|Xs],N)->rotate(Xs++[X],N-1).%% Prints a string and rotates itprint_rotate(S)->print_rotate(S,length(S)).print_rotate(_,0)->io:format("~n"),ok;print_rotate(S,N)->NewS=rotate(S,1),io:format("~s ",[NewS]),print_rotate(NewS,N-1).%% Reads the string from STDINrotate_string()->caseio:fread("","~s")ofeof->ok;{ok,[S]}->print_rotate(S),rotate_string()end.main()->{ok,[_]}=io:fread("","~d"),rotate_string().
Rotate String
You are viewing a single comment's thread. Return to all comments →
Erlang: