Rutas
/
Factor
Factor
/
Ejercicios
/
Cadena alimentaria
Cadena alimentaria

Cadena alimentaria

Media

Instrucciones

Genera la letra de la canción «I Know an Old Lady Who Swallowed a Fly».

Aunque podrías copiar y pegar la letra, o leerla desde un fichero, este problema es mucho más interesante si lo abordas de forma algorítmica.

Esta es una canción acumulativa de origen desconocido.

Esta es una de las muchas variantes habituales.

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!

Particularidades de Factor

Implementa la palabra:

food-chain ( start end -- lines )

start y end son números de estrofa (1 para la mosca, hasta 8 para el caballo), ambos inclusive. Devuelve las estrofas solicitadas como una secuencia de strings, un string por cada línea de la canción.

Cuando se solicite más de una estrofa, separa las estrofas consecutivas con un único string vacío ("") para que las estrofas se muestren con una línea en blanco entre ellas. No hay ninguna línea en blanco al final después de la última estrofa.

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."
!    }

Fuente

WikipediaEl enlace se abre en una nueva ventana o pestaña
Editar en GitHub El enlace se abre en una ventana o pestaña nueva
Factor Exercism

¿Listo para empezar Cadena alimentaria?

Regístrate en Exercism para aprender y dominar Factor con 47 conceptos163 ejercicios y mentoría humana real, todo gratis.