Kurzusok
/
Haskell
Haskell
/
Feladatok
/
Tizenkét nap
Tizenkét nap

Tizenkét nap

Könnyű

Utasítások

Ebben a feladatban olyan kódot kell írnod, amely visszaadja a(z) »The Twelve Days of Christmas« című dal szövegét.

A »The Twelve Days of Christmas« egy közismert angol karácsonyi dal. A dal minden további versszaka az előző versszakra épül.

A kódod által visszaadott dalszövegnek pontosan meg kell egyeznie az alább látható teljes dalszöveggel.

Dalszöveg

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.

Tippek

Meg kell valósítanod a recite függvényt, amely kiírja a „The Twelve Days of Christmas” dal szövegét. Használhatod a megadott szignatúrát, ha bizonytalan vagy a típusokban, de ne hagyd, hogy korlátozza a kreativitásodat.

Ez a feladat szöveges adatokkal dolgozik. Történelmi okokból a Haskell String típusa ugyanaz, mint a [Char], azaz karakterek listája. A szöveges adatok hatékonyabb kezeléséhez a Text típus használható.

A feladat opcionális kiterjesztéseként

import qualified Data.Text as T
import           Data.Text (Text)
  • írhatsz például recite :: Int -> Int -> [Text]-et, és például T.pack néven hivatkozhatsz a Data.Text kombinatorokra.
  • kikeresheted a Data.Text dokumentációját.
  • lecserélheted a String összes előfordulását Text-re a TwelveDays.hs fájlban, azaz:
recite :: Int -> Int -> [Text]

Ez a rész teljesen opcionális.


Forrás

WikipediaA hivatkozás új ablakban vagy lapon nyílik meg
Szerkesztés GitHubon A hivatkozás új ablakban vagy lapon nyílik meg
Haskell Exercism

Készen állsz elkezdeni a(z) Tizenkét nap feladatot?

Iratkozz fel az Exercism-re, hogy megtanuld és elsajátítsd a(z) Haskell nyelvet 107 feladat segítségével, valódi emberi mentorálással, mindez ingyen.