fork(1) download
  1. -module(prog).
  2.  
  3. -define(SIDES, 4).
  4.  
  5. -export([main/0]).
  6.  
  7.  
  8. main() ->
  9. msg2rect("helloworldhelloworld").
  10.  
  11. msg2rect(Message) ->
  12. VChars = length(Message) div ?SIDES,
  13. HChars = VChars + trunc(((length(Message) rem ?SIDES) / 2)),
  14. {Half1, Half2} = lists:split(trunc(length(Message) / 2), Message),
  15. {Top, Rest1} = lists:split(HChars, Half1),
  16. {Bottom, Rest2} = lists:split(HChars, Half2),
  17. io:format("~s~n", [Top]),
  18. msg2rect(lists:append([Rest1, Rest2]), HChars - 2),
  19. io:format("~s~n", [lists:reverse(Bottom)]).
  20.  
  21. msg2rect([], _) ->
  22. ok;
  23. msg2rect([H|T], WSpaces) ->
  24. {Middle, Last} = lists:split(length(T) - 1, T),
  25. io:format("~s~s~s~n", [Last, lists:flatten(lists:duplicate(WSpaces, " ")), lists:flatten([H])]),
  26. msg2rect(Middle, WSpaces).
Success #stdin #stdout 0.21s 8448KB
stdin
Standard input is empty
stdout
hello
d   w
l   o
r   r
o   l
w   d
olleh