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

Difficulty: EASY
Tags: String algorithms

Starter code:
def align_right(text, width):
	

Solutions:
import textwrap

def align_right(text, width):
	return '\n'.join([l.rjust(width, ' ') for l in textwrap.wrap(text, width)])


def align_right(text, width):
	res = []
	line = []
	for word in text.split():
		if len(' '.join(line + [word])) <= width:
			line.append(word)
		else:
			res.append(line)
			line = [word]
	res.append(line)
	return '\n'.join((' '.join(line).rjust(width) for line in res))


from textwrap import TextWrapper

def align_right(text, width):
	tw = TextWrapper(width, break_on_hyphens=False)
	return '\n'.join((a.rjust(width) for a in tw.wrap(text)))


import re

def align_right(text, width):
	return '\n'.join((' ' * (width - len(line)) + line for (line, sep) in re.findall('(.{,' + str(width) + '})( |$)', text) if line))


def align_right(text, width):
	answer = []
	splitted = text.split(' ')
	temp = ''
	i = 0
	while i < len(splitted):
		while i < len(splitted) and len(temp + splitted[i]) < width + 1:
			temp += splitted[i] + ' '
			i += 1
		temp = temp.strip()
		answer.append(' ' * (width - len(temp)) + temp)
		temp = ''
	return '\n'.join(answer)


def align_right(text, width):
	k = text.split()
	out = ''
	last = []
	for x in k:
		if len(x + out) <= width:
			out += x + ' '
		else:
			last.append(out)
			out = x + ' '
	last.append(out)
	return '\n'.join((' ' * (width - len(x.rstrip())) + x.rstrip() for x in last))


def align_right(s, n):
	return '\n'.join([i.rjust(n, ' ') for i in __import__('textwrap').wrap(width=n, text=s)])


import textwrap

def align_right(text, width):
	wrapper = textwrap.TextWrapper(width=width, break_on_hyphens=True)
	return '\n'.join((line.rjust(width) for line in wrapper.wrap(text)))


from textwrap import wrap

def align_right(text, width):
	return '\n'.join((line.rjust(width) for line in wrap(text, width=width, break_on_hyphens=False)))


def align_right(text, width):
	lines = []
	while len(text) > width:
		cut = text[:width + 1].rfind(' ')
		lines.append(text[:cut].rjust(width))
		text = text[cut + 1:]
	lines.append(text.rjust(width))
	return '\n'.join(lines)