Doze dias

Doze dias

Fácil

Instruções

Sua tarefa neste exercício é escrever um código que retorne a letra da música: "The Twelve Days of Christmas."

"The Twelve Days of Christmas" é uma canção natalina inglesa comum. Cada estrofe seguinte da música se baseia na estrofe anterior.

A letra que seu código retorna deve corresponder exatamente ao texto completo da música mostrado abaixo.

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.

Dicas

Você precisa implementar a função recite, que gera a letra de 'The Twelve Days of Christmas'. Você pode usar a assinatura fornecida se não tiver certeza sobre os tipos, mas não deixe que ela limite sua criatividade.

Este exercício trabalha com dados textuais. Por razões históricas, o tipo String de Haskell é sinônimo de [Char], uma lista de caracteres. Para lidar com dados textuais de forma mais eficiente, é possível usar o tipo Text.

Como uma extensão opcional deste exercício, você pode

import qualified Data.Text as T
import           Data.Text (Text)
  • escrever, por exemplo, recite :: Int -> Int -> [Text] e se referir aos combinadores de Data.Text como, por exemplo, T.pack.
  • consultar a documentação de Data.Text.
  • substituir todas as ocorrências de String por Text em TwelveDays.hs, ou seja:
recite :: Int -> Int -> [Text]

Esta parte é totalmente opcional.


Fonte

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

Tudo pronto para começar Doze dias?

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