Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Fibonacci Poem by Pactp
def fibo_poem(text: str) -> str:
def fib() -> int:
prev, curr = 0, 1
while True:
yield curr
prev, curr = curr, prev + curr
f = fib()
words = text.replace('\n', ' ').replace(' ', ' ').split(' ')
lines = []
n0, n1 = 0, next(f)
while n0 < len(words):
line = words[n0:n1]
if len(line) < n1 - n0:
line.extend(['_']*(n1 - n0 - len(line)))
lines.append(' '.join(line))
n0,n1 = n1, n1 + next(f)
return '\n'.join(lines)
March 27, 2023
Comments: