Doze Dias

Doze Dias

Fácil

Instruções

Neste exercício, a tua tarefa é escrever código que devolva a letra da canção: "The Twelve Days of Christmas".

"The Twelve Days of Christmas" é uma conhecida canção de Natal inglesa. Cada estrofe seguinte da canção baseia-se na anterior.

A letra que o teu código devolve deve corresponder exatamente ao texto completo da canção apresentado 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

Precisas de implementar a função recite, que produz a letra de 'The Twelve Days of Christmas'. Podes usar a assinatura fornecida se tiveres dúvidas sobre os tipos, mas não deixes que isso restrinja a tua criatividade.

Este exercício trabalha com dados textuais. Por razões históricas, o tipo String do Haskell é sinónimo de [Char], uma lista de carateres. Para um tratamento mais eficiente de dados textuais, podes usar o tipo Text.

Como extensão opcional deste exercício, podes

import qualified Data.Text as T
import           Data.Text (Text)
  • escrever, por exemplo, recite :: Int -> Int -> [Text] e referir os 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 numa nova janela ou separador
Editar via GitHub A ligação abre numa nova janela ou separador
Haskell Exercism

Estás pronto para começar Doze Dias?

Inscreve-te no Exercism para aprenderes e dominares Haskell com 107 exercícios, e mentoria humana real, tudo grátis.