Skip to content

Commit 5f1bb80

Browse files
Add twelve-days exercise (#169)
1 parent e552175 commit 5f1bb80

File tree

13 files changed

+486
-0
lines changed

13 files changed

+486
-0
lines changed

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@
135135
"prerequisites": [],
136136
"difficulty": 3
137137
},
138+
{
139+
"slug": "twelve-days",
140+
"name": "Twelve Days",
141+
"uuid": "fd218a7d-3c39-473b-a71b-ff984ea58b86",
142+
"practices": [],
143+
"prerequisites": [],
144+
"difficulty": 5
145+
},
138146
{
139147
"slug": "house",
140148
"name": "House",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Instruction append
2+
3+
Each verse should end with a newline `\n`, with no additional delimiter.
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"root": true,
3+
"extends": "@exercism/eslint-config-javascript",
4+
"env": {
5+
"jest": true
6+
},
7+
"overrides": [
8+
{
9+
"files": [
10+
"*.spec.js"
11+
],
12+
"excludedFiles": [
13+
"custom.spec.js"
14+
],
15+
"extends": "@exercism/eslint-config-javascript/maintainers"
16+
}
17+
]
18+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"authors": [
3+
"keiravillekode"
4+
],
5+
"files": {
6+
"solution": [
7+
"twelve-days.wat"
8+
],
9+
"test": [
10+
"twelve-days.spec.js"
11+
],
12+
"example": [
13+
".meta/proof.ci.wat"
14+
],
15+
"invalidator": [
16+
"package.json"
17+
]
18+
},
19+
"blurb": "Output the lyrics to 'The Twelve Days of Christmas'.",
20+
"source": "Wikipedia",
21+
"source_url": "https://en.wikipedia.org/wiki/The_Twelve_Days_of_Christmas_(song)",
22+
"custom": {
23+
"version.tests.compatibility": "jest-27",
24+
"flag.tests.task-per-describe": false,
25+
"flag.tests.may-run-long": false,
26+
"flag.tests.includes-optional": false
27+
}
28+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
(module
2+
(memory (export "mem") 1)
3+
4+
(data (i32.const 0) "On the ")
5+
6+
(data (i32.const 10) "firstsecondthirdfourthfifthsixthseventheighthninthtentheleventhtwelfth")
7+
8+
;; 8 bit offsets [0, 0, 5, 11, 16, 22, 27, 32, 39, 45, 50, 55, 63, 70]
9+
(data (i32.const 80) "\00\00\05\0b\10\16\1b\20\27\2d\32\37\3f\46\46")
10+
11+
(data (i32.const 110) " day of Christmas my true love gave to me: ")
12+
13+
(data (i32.const 160) "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.\n")
14+
15+
;; 8 bit offsets [0, 235, 213, 194, 174, 157, 137, 113, 90, 69, 48, 26, 0]
16+
(data (i32.const 430) "\00\eb\d5\c2\ae\9d\89\71\5a\45\30\1a\00")
17+
18+
(global $ON_THE_OFFSET i32 (i32.const 0))
19+
20+
(global $ON_THE_LENGTH i32 (i32.const 7))
21+
22+
(global $ORDINALS_OFFSET i32 (i32.const 10))
23+
24+
(global $ORDINALS_TABLE_OFFSET i32 (i32.const 80))
25+
26+
(global $DAY_OF_OFFSET i32 (i32.const 110))
27+
28+
(global $DAY_OF_LENGTH i32 (i32.const 43))
29+
30+
(global $GIFTS_OFFSET i32 (i32.const 160))
31+
32+
(global $GIFTS_LENGTH i32 (i32.const 263))
33+
34+
(global $GIFTS_TABLE_OFFSET i32 (i32.const 430))
35+
36+
(global $OUTPUT i32 (i32.const 460))
37+
38+
;;
39+
;; Lyrics to 'The Twelve Days of Christmas'.
40+
;;
41+
;; @param {i32} startVerse - The initial verse to recite
42+
;; @param {i32} endVerse - The final verse to recite
43+
;;
44+
;; @returns {(i32,i32)} - Offset and length of result string
45+
;; in linear memory.
46+
;;
47+
(func (export "recite") (param $startVerse i32) (param $endVerse i32) (result i32 i32)
48+
(local $dest i32)
49+
(local $verse i32)
50+
(local $offset i32)
51+
(local $length i32)
52+
53+
(local.set $dest (global.get $OUTPUT))
54+
(local.set $verse (local.get $startVerse))
55+
56+
(loop $LOOP
57+
(memory.copy (local.get $dest)
58+
(global.get $ON_THE_OFFSET)
59+
(global.get $ON_THE_LENGTH))
60+
(local.set $dest (i32.add (local.get $dest)
61+
(global.get $ON_THE_LENGTH)))
62+
63+
(local.set $offset (i32.add (global.get $ORDINALS_TABLE_OFFSET)
64+
(local.get $verse)))
65+
(local.set $length (i32.load8_u (i32.add (local.get $offset)
66+
(i32.const 1))))
67+
(local.set $offset (i32.load8_u (local.get $offset)))
68+
(local.set $length (i32.sub (local.get $length)
69+
(local.get $offset)))
70+
(memory.copy (local.get $dest)
71+
(i32.add (local.get $offset) (global.get $ORDINALS_OFFSET))
72+
(local.get $length))
73+
(local.set $dest (i32.add (local.get $dest)
74+
(local.get $length)))
75+
76+
(memory.copy (local.get $dest)
77+
(global.get $DAY_OF_OFFSET)
78+
(global.get $DAY_OF_LENGTH))
79+
(local.set $dest (i32.add (local.get $dest)
80+
(global.get $DAY_OF_LENGTH)))
81+
82+
(local.set $offset (i32.load8_u (i32.add (global.get $GIFTS_TABLE_OFFSET)
83+
(local.get $verse))))
84+
(local.set $length (i32.sub (global.get $GIFTS_LENGTH)
85+
(local.get $offset)))
86+
(memory.copy (local.get $dest)
87+
(i32.add (local.get $offset) (global.get $GIFTS_OFFSET))
88+
(local.get $length))
89+
(local.set $dest (i32.add (local.get $dest)
90+
(local.get $length)))
91+
92+
(local.set $verse (i32.add (local.get $verse)
93+
(i32.const 1)))
94+
(br_if $LOOP (i32.le_u (local.get $verse)
95+
(local.get $endVerse)))
96+
)
97+
98+
(return (global.get $OUTPUT) (i32.sub (local.get $dest)
99+
(global.get $OUTPUT)))
100+
)
101+
)
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"

exercises/practice/twelve-days/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
audit=false
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Exercism
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default {
2+
presets: ["@exercism/babel-preset-javascript"],
3+
plugins: [],
4+
};

0 commit comments

Comments
 (0)