Skip to content

Commit a2d9070

Browse files
authored
twelve-days (#53)
1 parent bb5f94f commit a2d9070

9 files changed

Lines changed: 279 additions & 0 deletions

File tree

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,14 @@
406406
"practices": [],
407407
"prerequisites": [],
408408
"difficulty": 4
409+
},
410+
{
411+
"slug": "twelve-days",
412+
"name": "Twelve Days",
413+
"uuid": "69322771-7756-42a9-a79b-8700ce877700",
414+
"practices": [],
415+
"prerequisites": [],
416+
"difficulty": 4
409417
}
410418
]
411419
},
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
return {
2+
default = {
3+
ROOT = { '.' }
4+
}
5+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Instructions
2+
3+
Your task in this exercise is to write code that returns the lyrics of the song: "The Twelve Days of Christmas."
4+
5+
"The Twelve Days of Christmas" is a common English Christmas carol.
6+
Each subsequent verse of the song builds on the previous verse.
7+
8+
The lyrics your code returns should _exactly_ match the full song text shown below.
9+
10+
## Lyrics
11+
12+
```text
13+
On the first day of Christmas my true love gave to me: a Partridge in a Pear Tree.
14+
15+
On the second day of Christmas my true love gave to me: two Turtle Doves, and a Partridge in a Pear Tree.
16+
17+
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.
18+
19+
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.
20+
21+
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.
22+
23+
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.
24+
25+
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.
26+
27+
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.
28+
29+
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.
30+
31+
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.
32+
33+
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.
34+
35+
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.
36+
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"authors": [
3+
"glennj"
4+
],
5+
"files": {
6+
"solution": [
7+
"twelve_days.moon"
8+
],
9+
"test": [
10+
"twelve_days_spec.moon"
11+
],
12+
"example": [
13+
".meta/example.moon"
14+
]
15+
},
16+
"blurb": "Output the lyrics to 'The Twelve Days of Christmas'.",
17+
"source": "Wikipedia",
18+
"source_url": "https://en.wikipedia.org/wiki/The_Twelve_Days_of_Christmas_(song)"
19+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
nth = { 'first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh',
2+
'eighth', 'ninth', 'tenth', 'eleventh', 'twelfth' }
3+
4+
presents = {
5+
'a Partridge in a Pear Tree',
6+
'two Turtle Doves',
7+
'three French Hens',
8+
'four Calling Birds',
9+
'five Gold Rings',
10+
'six Geese-a-Laying',
11+
'seven Swans-a-Swimming',
12+
'eight Maids-a-Milking',
13+
'nine Ladies Dancing',
14+
'ten Lords-a-Leaping',
15+
'eleven Pipers Piping',
16+
'twelve Drummers Drumming',
17+
}
18+
19+
gifts = (n) ->
20+
items = {}
21+
table.insert items, 1, presents[i] for i = 1, n
22+
items[#items] = "and #{items[#items]}" if n > 1
23+
table.concat items, ', '
24+
25+
26+
verse = (n) ->
27+
"On the #{nth[n]} day of Christmas my true love gave to me: #{gifts n}."
28+
29+
{
30+
recite: (start, stop) -> [verse i for i = start, stop]
31+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
str_list = (list, level) ->
2+
if #list <= 1
3+
"{#{table.concat [quote elem for elem in *list], ', '}}"
4+
else
5+
item = [indent quote(elem) .. ',', level + 1 for elem in *list]
6+
table.insert item, 1, '{'
7+
table.insert item, indent('}', level)
8+
table.concat item, '\n'
9+
10+
11+
{
12+
module_name: 'TwelveDays',
13+
14+
generate_test: (case, level) ->
15+
lines = {
16+
"result = TwelveDays.#{case.property} #{case.input.startVerse}, #{case.input.endVerse}",
17+
"expected = #{str_list case.expected, level}",
18+
"assert.are.same expected, result"
19+
}
20+
table.concat [indent line, level for line in *lines], '\n'
21+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
11+
12+
[c0b5a5e6-c89d-49b1-a6b2-9f523bff33f7]
13+
description = "verse -> first day a partridge in a pear tree"
14+
15+
[1c64508a-df3d-420a-b8e1-fe408847854a]
16+
description = "verse -> second day two turtle doves"
17+
18+
[a919e09c-75b2-4e64-bb23-de4a692060a8]
19+
description = "verse -> third day three french hens"
20+
21+
[9bed8631-ec60-4894-a3bb-4f0ec9fbe68d]
22+
description = "verse -> fourth day four calling birds"
23+
24+
[cf1024f0-73b6-4545-be57-e9cea565289a]
25+
description = "verse -> fifth day five gold rings"
26+
27+
[50bd3393-868a-4f24-a618-68df3d02ff04]
28+
description = "verse -> sixth day six geese-a-laying"
29+
30+
[8f29638c-9bf1-4680-94be-e8b84e4ade83]
31+
description = "verse -> seventh day seven swans-a-swimming"
32+
33+
[7038d6e1-e377-47ad-8c37-10670a05bc05]
34+
description = "verse -> eighth day eight maids-a-milking"
35+
36+
[37a800a6-7a56-4352-8d72-0f51eb37cfe8]
37+
description = "verse -> ninth day nine ladies dancing"
38+
39+
[10b158aa-49ff-4b2d-afc3-13af9133510d]
40+
description = "verse -> tenth day ten lords-a-leaping"
41+
42+
[08d7d453-f2ba-478d-8df0-d39ea6a4f457]
43+
description = "verse -> eleventh day eleven pipers piping"
44+
45+
[0620fea7-1704-4e48-b557-c05bf43967f0]
46+
description = "verse -> twelfth day twelve drummers drumming"
47+
48+
[da8b9013-b1e8-49df-b6ef-ddec0219e398]
49+
description = "lyrics -> recites first three verses of the song"
50+
51+
[c095af0d-3137-4653-ad32-bfb899eda24c]
52+
description = "lyrics -> recites three verses from the middle of the song"
53+
54+
[20921bc9-cc52-4627-80b3-198cbbfcf9b7]
55+
description = "lyrics -> recites the whole song"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
recite: (start, stop) ->
3+
error 'Implement me'
4+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
TwelveDays = require 'twelve_days'
2+
3+
describe 'twelve-days', ->
4+
describe 'verse', ->
5+
it 'first day a partridge in a pear tree', ->
6+
result = TwelveDays.recite 1, 1
7+
expected = {'On the first day of Christmas my true love gave to me: a Partridge in a Pear Tree.'}
8+
assert.are.same expected, result
9+
10+
pending 'second day two turtle doves', ->
11+
result = TwelveDays.recite 2, 2
12+
expected = {'On the second day of Christmas my true love gave to me: two Turtle Doves, and a Partridge in a Pear Tree.'}
13+
assert.are.same expected, result
14+
15+
pending 'third day three french hens', ->
16+
result = TwelveDays.recite 3, 3
17+
expected = {'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.'}
18+
assert.are.same expected, result
19+
20+
pending 'fourth day four calling birds', ->
21+
result = TwelveDays.recite 4, 4
22+
expected = {'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.'}
23+
assert.are.same expected, result
24+
25+
pending 'fifth day five gold rings', ->
26+
result = TwelveDays.recite 5, 5
27+
expected = {'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.'}
28+
assert.are.same expected, result
29+
30+
pending 'sixth day six geese-a-laying', ->
31+
result = TwelveDays.recite 6, 6
32+
expected = {'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.'}
33+
assert.are.same expected, result
34+
35+
pending 'seventh day seven swans-a-swimming', ->
36+
result = TwelveDays.recite 7, 7
37+
expected = {'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.'}
38+
assert.are.same expected, result
39+
40+
pending 'eighth day eight maids-a-milking', ->
41+
result = TwelveDays.recite 8, 8
42+
expected = {'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.'}
43+
assert.are.same expected, result
44+
45+
pending 'ninth day nine ladies dancing', ->
46+
result = TwelveDays.recite 9, 9
47+
expected = {'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.'}
48+
assert.are.same expected, result
49+
50+
pending 'tenth day ten lords-a-leaping', ->
51+
result = TwelveDays.recite 10, 10
52+
expected = {'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.'}
53+
assert.are.same expected, result
54+
55+
pending 'eleventh day eleven pipers piping', ->
56+
result = TwelveDays.recite 11, 11
57+
expected = {'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.'}
58+
assert.are.same expected, result
59+
60+
pending 'twelfth day twelve drummers drumming', ->
61+
result = TwelveDays.recite 12, 12
62+
expected = {'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.'}
63+
assert.are.same expected, result
64+
65+
describe 'lyrics', ->
66+
pending 'recites first three verses of the song', ->
67+
result = TwelveDays.recite 1, 3
68+
expected = {
69+
'On the first day of Christmas my true love gave to me: a Partridge in a Pear Tree.',
70+
'On the second day of Christmas my true love gave to me: two Turtle Doves, and a Partridge in a Pear Tree.',
71+
'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.',
72+
}
73+
assert.are.same expected, result
74+
75+
pending 'recites three verses from the middle of the song', ->
76+
result = TwelveDays.recite 4, 6
77+
expected = {
78+
'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.',
79+
'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.',
80+
'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.',
81+
}
82+
assert.are.same expected, result
83+
84+
pending 'recites the whole song', ->
85+
result = TwelveDays.recite 1, 12
86+
expected = {
87+
'On the first day of Christmas my true love gave to me: a Partridge in a Pear Tree.',
88+
'On the second day of Christmas my true love gave to me: two Turtle Doves, and a Partridge in a Pear Tree.',
89+
'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.',
90+
'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.',
91+
'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.',
92+
'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.',
93+
'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.',
94+
'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.',
95+
'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.',
96+
'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.',
97+
'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.',
98+
'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.',
99+
}
100+
assert.are.same expected, result

0 commit comments

Comments
 (0)