6 kyu

Text align right

228 of 408depperm

Description:

Your task in this Kata is to emulate text justify right in monospace font. You will be given a single-lined text and the expected justification width. The longest word will never be greater than this width.

Here are the rules:

  • Use spaces to fill in the gaps on the left side of the words.
  • Each line should contain as many words as possible.
  • Use '\n' to separate lines.
  • Gap between words can't differ by more than one space.
  • Lines should end with a word not a space.
  • '\n' is not included in the length of a line.
  • Last line should not contain '\n'

Example with width=30:

        Bacon ipsum dolor amet
excepteur ut kevin burgdoggen,
   shankle cupim dolor officia
       ground round id ullamco
   deserunt nisi. Commodo tail
    qui salami, brisket boudin 
tri-tip. Labore flank laboris,
  cow enim proident aliqua sed
      hamburger consequat. Sed
     consequat ut non bresaola
   capicola shoulder excepteur
 veniam, bacon kevin. Pastrami
   shank laborum est excepteur
 non eiusmod bresaola flank in
nostrud. Corned beef ex pig do
   kevin filet mignon in irure
 deserunt ipsum qui duis short
        loin. Beef ribs dolore
  meatball officia rump fugiat
  in enim corned beef non est.

If you enjoyed this one and want more of a challenge try https://www.codewars.com/kata/text-align-justify/python

If you like bacon ipsum https://baconipsum.com

Algorithms
Strings

More By Author:

Check out these other kata created by depperm

Stats:

CreatedNov 23, 2016
PublishedNov 23, 2016
Warriors Trained1062
Total Skips22
Total Code Submissions3018
Total Times Completed408
Python Completions228
JavaScript Completions194
Total Stars33
% of votes with a positive feedback rating97% of 137
Total "Very Satisfied" Votes128
Total "Somewhat Satisfied" Votes9
Total "Not Satisfied" Votes0
Total Rank Assessments10
Average Assessed Rank
5 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • depperm Avatar
  • tachyonlabs Avatar
  • hobovsky Avatar
Ad