Track
/
Haskell
Haskell
/
Esercizi
/
I dodici giorni
I dodici giorni

I dodici giorni

Facile

Istruzioni

In questo esercizio il tuo compito è scrivere del codice che restituisca il testo della canzone «The Twelve Days of Christmas».

«The Twelve Days of Christmas» è un canto di Natale inglese molto diffuso. Ogni strofa successiva si basa su quella precedente.

Il testo restituito dal codice deve corrispondere esattamente al testo completo della canzone mostrato qui sotto.

Testo

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.

Suggerimenti

Devi implementare la funzione recite, che restituisce il testo di «The Twelve Days of Christmas». Puoi usare la firma fornita se hai dubbi sui tipi, ma non lasciare che limiti la tua creatività.

Questo esercizio lavora con dati testuali. Per ragioni storiche, il tipo String di Haskell è sinonimo di [Char], una lista di caratteri. Per gestire i dati testuali in modo più efficiente si può usare il tipo Text.

Come estensione facoltativa di questo esercizio, puoi

import qualified Data.Text as T
import           Data.Text (Text)
  • scrivere ad es. recite :: Int -> Int -> [Text] e riferirti ai combinatori di Data.Text come ad es. T.pack.
  • consultare la documentazione di Data.Text.
  • sostituire tutte le occorrenze di String con Text in TwelveDays.hs, cioè:
recite :: Int -> Int -> [Text]

Questa parte è del tutto facoltativa.


Fonte

WikipediaIl link si apre in una nuova finestra o scheda
Modifica tramite GitHub Il link si apre in una nuova finestra o scheda
Haskell Exercism

Vuoi iniziare I dodici giorni?

Iscriviti a Exercism per imparare e padroneggiare Haskell con 107 esercizi e il mentoring di persone reali, tutto gratis.