열두 날

열두 날

쉬움

지침

이 연습 문제에서 해야 할 일은 "The Twelve Days of Christmas"라는 노래의 가사를 반환하는 코드를 작성하는 거예요.

"The Twelve Days of Christmas"는 널리 알려진 영어 크리스마스 캐럴이에요. 노래의 각 절은 그 앞 절에 이어서 내용이 쌓여 가요.

코드가 반환하는 가사는 아래에 나온 전체 노랫말과 정확히 일치해야 해요.

가사

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.

힌트

'The Twelve Days of Christmas'의 가사를 출력하는 recite 함수를 구현해야 해요. 타입이 확실하지 않다면 제공된 시그니처를 사용해도 되지만, 그것이 창의성을 제한하도록 두지는 마세요.

이 연습 문제는 텍스트 데이터를 다뤄요. 역사적인 이유로, Haskell의 String 타입은 문자들의 리스트인 [Char]와 같은 의미예요. 텍스트 데이터를 더 효율적으로 다루려면 Text 타입을 사용할 수 있어요.

이 연습 문제를 선택적으로 확장해서 다음과 같이 해볼 수 있어요.

import qualified Data.Text as T
import           Data.Text (Text)
  • 예를 들어 recite :: Int -> Int -> [Text]처럼 작성하고, Data.Text 컴비네이터를 T.pack처럼 참조해요.
  • Data.Text 문서를 찾아봐요.
  • TwelveDays.hs에서 모든 String을 Text로 바꿔요. 즉:
recite :: Int -> Int -> [Text]

이 부분은 전적으로 선택 사항이에요.


출처

Wikipedia링크가 새 창이나 탭에서 열려요
GitHub에서 편집 링크가 새 창이나 탭에서 열려요
Haskell Exercism

열두 날 문제를 시작해 볼 준비가 됐나요?

Exercism에 가입하고 Haskell 트랙을 연습 문제 107개, 그리고 실제 사람의 멘토링과 함께 배우고 익혀 보세요. 모두 무료예요.