Created
February 1, 2013 23:10
-
-
Save efcasado/4694814 to your computer and use it in GitHub Desktop.
Solucion para la kata 'rectangulos de texto'.
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(kata). | |
-define(SIDES, 4). | |
-export([msg2rect/1]). | |
msg2rect(Message) -> | |
VChars = length(Message) div ?SIDES, | |
HChars = VChars + trunc(((length(Message) rem ?SIDES) / 2)), | |
{Half1, Half2} = lists:split(trunc(length(Message) / 2), Message), | |
{Top, Rest1} = lists:split(HChars, Half1), | |
{Bottom, Rest2} = lists:split(HChars, Half2), | |
io:format("~s~n", [Top]), | |
msg2rect(lists:append([Rest1, Rest2]), HChars - 2), | |
io:format("~s~n", [lists:reverse(Bottom)]). | |
msg2rect([], _) -> | |
ok; | |
msg2rect([H|T], WSpaces) -> | |
{Middle, Last} = lists:split(length(T) - 1, T), | |
io:format("~s~s~s~n", [Last, lists:flatten(lists:duplicate(WSpaces, " ")), lists:flatten([H])]), | |
msg2rect(Middle, WSpaces). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment