Trilhas
/
Factor
Factor
/
Exercícios
/
Cadeia alimentar
Cadeia alimentar

Cadeia alimentar

Médio

Instruções

Gere a letra da música 'I Know an Old Lady Who Swallowed a Fly'.

Você até poderia copiar e colar a letra, ou lê-la de um arquivo, mas este problema fica muito mais interessante se você o abordar de forma algorítmica.

Esta é uma canção cumulativa de origem desconhecida.

Esta é uma entre muitas variantes comuns.

I know an old lady who swallowed a fly.
I don't know why she swallowed the fly. Perhaps she'll die.

I know an old lady who swallowed a spider.
It wriggled and jiggled and tickled inside her.
She swallowed the spider to catch the fly.
I don't know why she swallowed the fly. Perhaps she'll die.

I know an old lady who swallowed a bird.
How absurd to swallow a bird!
She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.
She swallowed the spider to catch the fly.
I don't know why she swallowed the fly. Perhaps she'll die.

I know an old lady who swallowed a cat.
Imagine that, to swallow a cat!
She swallowed the cat to catch the bird.
She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.
She swallowed the spider to catch the fly.
I don't know why she swallowed the fly. Perhaps she'll die.

I know an old lady who swallowed a dog.
What a hog, to swallow a dog!
She swallowed the dog to catch the cat.
She swallowed the cat to catch the bird.
She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.
She swallowed the spider to catch the fly.
I don't know why she swallowed the fly. Perhaps she'll die.

I know an old lady who swallowed a goat.
Just opened her throat and swallowed a goat!
She swallowed the goat to catch the dog.
She swallowed the dog to catch the cat.
She swallowed the cat to catch the bird.
She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.
She swallowed the spider to catch the fly.
I don't know why she swallowed the fly. Perhaps she'll die.

I know an old lady who swallowed a cow.
I don't know how she swallowed a cow!
She swallowed the cow to catch the goat.
She swallowed the goat to catch the dog.
She swallowed the dog to catch the cat.
She swallowed the cat to catch the bird.
She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.
She swallowed the spider to catch the fly.
I don't know why she swallowed the fly. Perhaps she'll die.

I know an old lady who swallowed a horse.
She's dead, of course!

Especificidades do Factor

Implemente a palavra:

food-chain ( start end -- lines )

start e end são números de verso (1 para a mosca, até 8 para o cavalo), inclusive. Retorne os versos pedidos como uma sequência de strings, uma string por linha da música.

Quando mais de um verso for pedido, separe versos consecutivos com uma única string vazia ("") para que os versos sejam renderizados com uma linha em branco entre eles. Não há linha em branco no final depois do último verso.

1 2 food-chain .
! => {
!        "I know an old lady who swallowed a fly."
!        "I don't know why she swallowed the fly. Perhaps she'll die."
!        ""
!        "I know an old lady who swallowed a spider."
!        "It wriggled and jiggled and tickled inside her."
!        "She swallowed the spider to catch the fly."
!        "I don't know why she swallowed the fly. Perhaps she'll die."
!    }

Fonte

WikipediaO link abre em uma nova janela ou aba
Editar via GitHub O link abre em uma nova janela ou aba
Factor Exercism

Tudo pronto para começar Cadeia alimentar?

Crie sua conta no Exercism para aprender e dominar Factor com 47 conceitos163 exercícios e mentoria humana de verdade, tudo de graça.