Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Fibonacci Poem by joe_5588
def fibo_poem(text: str) -> str:
if text == '':
return text
# m previous value, n current value, o total of sequence based on previous value
m, n, o = 0, 1, 0
textlist = text.split()
output = ''
while o < len(textlist):
check = len(textlist[o:o + n])
if check < n:
line = ' '.join(textlist[o:o + n]) + ' _' * (n - check)
else:
line = ' '.join(textlist[o:o + n])
output += line + '\n'
m, n = n, m + n
o += m
return output.rstrip('\n')
Sept. 11, 2023