Doce días

Doce días

Fácil

Instrucciones

Tu tarea en este ejercicio es escribir código que devuelva la letra de la canción: «The Twelve Days of Christmas».

«The Twelve Days of Christmas» es un conocido villancico inglés. Cada estrofa de la canción se basa en la estrofa anterior.

La letra que devuelva tu código debe coincidir exactamente con el texto completo de la canción que se muestra a continuación.

Letra

On the first day of Christmas my true love gave to me: a Partridge in a Pear Tree.

On the second day of Christmas my true love gave to me: two Turtle Doves, and a Partridge in a Pear Tree.

On the third day of Christmas my true love gave to me: three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.

On the fourth day of Christmas my true love gave to me: four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.

On the fifth day of Christmas my true love gave to me: five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.

On the sixth day of Christmas my true love gave to me: six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.

On the seventh day of Christmas my true love gave to me: seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.

On the eighth day of Christmas my true love gave to me: eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.

On the ninth day of Christmas my true love gave to me: nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.

On the tenth day of Christmas my true love gave to me: ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.

On the eleventh day of Christmas my true love gave to me: eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.

On the twelfth day of Christmas my true love gave to me: twelve Drummers Drumming, eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.

Pistas

Necesitas implementar la función recite, que produce la letra de «The Twelve Days of Christmas». Puedes usar la signatura que te damos si tienes dudas sobre los tipos, pero no dejes que limite tu creatividad.

Este ejercicio trabaja con datos textuales. Por razones históricas, el tipo String de Haskell es sinónimo de [Char], una lista de caracteres. Para manejar datos textuales de forma más eficiente, se puede usar el tipo Text.

Como extensión opcional de este ejercicio, puedes

import qualified Data.Text as T
import           Data.Text (Text)
  • escribir, por ejemplo, recite :: Int -> Int -> [Text] y referirte a los combinadores de Data.Text como, por ejemplo, T.pack.
  • buscar la documentación de Data.Text.
  • reemplazar todas las apariciones de String por Text en TwelveDays.hs, es decir:
recite :: Int -> Int -> [Text]

Esta parte es totalmente opcional.


Fuente

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

¿Todo listo para empezar Doce días?

Regístrate en Exercism para aprender y dominar Haskell con 107 ejercicios y mentoría humana real, todo gratis.