Skip to content

Commit 252f418

Browse files
authored
Add house (#105)
1 parent 9639f1d commit 252f418

9 files changed

Lines changed: 327 additions & 0 deletions

File tree

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,14 @@
282282
"prerequisites": [],
283283
"difficulty": 3
284284
},
285+
{
286+
"slug": "house",
287+
"name": "House",
288+
"uuid": "60a9a9e9-0b19-40cd-8d4c-d8f3af092d55",
289+
"practices": [],
290+
"prerequisites": [],
291+
"difficulty": 3
292+
},
285293
{
286294
"slug": "matrix",
287295
"name": "Matrix",

exercises/practice/house/.busted

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: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Instructions
2+
3+
Recite the nursery rhyme 'This is the House that Jack Built'.
4+
5+
> [The] process of placing a phrase of clause within another phrase of clause is called embedding.
6+
> It is through the processes of recursion and embedding that we are able to take a finite number of forms (words and phrases) and construct an infinite number of expressions.
7+
> Furthermore, embedding also allows us to construct an infinitely long structure, in theory anyway.
8+
9+
- [papyr.com][papyr]
10+
11+
The nursery rhyme reads as follows:
12+
13+
```text
14+
This is the house that Jack built.
15+
16+
This is the malt
17+
that lay in the house that Jack built.
18+
19+
This is the rat
20+
that ate the malt
21+
that lay in the house that Jack built.
22+
23+
This is the cat
24+
that killed the rat
25+
that ate the malt
26+
that lay in the house that Jack built.
27+
28+
This is the dog
29+
that worried the cat
30+
that killed the rat
31+
that ate the malt
32+
that lay in the house that Jack built.
33+
34+
This is the cow with the crumpled horn
35+
that tossed the dog
36+
that worried the cat
37+
that killed the rat
38+
that ate the malt
39+
that lay in the house that Jack built.
40+
41+
This is the maiden all forlorn
42+
that milked the cow with the crumpled horn
43+
that tossed the dog
44+
that worried the cat
45+
that killed the rat
46+
that ate the malt
47+
that lay in the house that Jack built.
48+
49+
This is the man all tattered and torn
50+
that kissed the maiden all forlorn
51+
that milked the cow with the crumpled horn
52+
that tossed the dog
53+
that worried the cat
54+
that killed the rat
55+
that ate the malt
56+
that lay in the house that Jack built.
57+
58+
This is the priest all shaven and shorn
59+
that married the man all tattered and torn
60+
that kissed the maiden all forlorn
61+
that milked the cow with the crumpled horn
62+
that tossed the dog
63+
that worried the cat
64+
that killed the rat
65+
that ate the malt
66+
that lay in the house that Jack built.
67+
68+
This is the rooster that crowed in the morn
69+
that woke the priest all shaven and shorn
70+
that married the man all tattered and torn
71+
that kissed the maiden all forlorn
72+
that milked the cow with the crumpled horn
73+
that tossed the dog
74+
that worried the cat
75+
that killed the rat
76+
that ate the malt
77+
that lay in the house that Jack built.
78+
79+
This is the farmer sowing his corn
80+
that kept the rooster that crowed in the morn
81+
that woke the priest all shaven and shorn
82+
that married the man all tattered and torn
83+
that kissed the maiden all forlorn
84+
that milked the cow with the crumpled horn
85+
that tossed the dog
86+
that worried the cat
87+
that killed the rat
88+
that ate the malt
89+
that lay in the house that Jack built.
90+
91+
This is the horse and the hound and the horn
92+
that belonged to the farmer sowing his corn
93+
that kept the rooster that crowed in the morn
94+
that woke the priest all shaven and shorn
95+
that married the man all tattered and torn
96+
that kissed the maiden all forlorn
97+
that milked the cow with the crumpled horn
98+
that tossed the dog
99+
that worried the cat
100+
that killed the rat
101+
that ate the malt
102+
that lay in the house that Jack built.
103+
```
104+
105+
[papyr]: https://papyr.com/hypertextbooks/grammar/ph_noun.htm
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+
"house.moon"
8+
],
9+
"test": [
10+
"house_spec.moon"
11+
],
12+
"example": [
13+
".meta/example.moon"
14+
]
15+
},
16+
"blurb": "Output the nursery rhyme 'This is the House that Jack Built'.",
17+
"source": "British nursery rhyme",
18+
"source_url": "https://en.wikipedia.org/wiki/This_Is_The_House_That_Jack_Built"
19+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
data = {
2+
{'house', 'Jack built.'}
3+
{'malt', 'lay in'}
4+
{'rat', 'ate'}
5+
{'cat', 'killed'}
6+
{'dog', 'worried'}
7+
{'cow with the crumpled horn', 'tossed'}
8+
{'maiden all forlorn', 'milked'}
9+
{'man all tattered and torn', 'kissed'}
10+
{'priest all shaven and shorn', 'married'}
11+
{'rooster that crowed in the morn', 'woke'}
12+
{'farmer sowing his corn', 'kept'}
13+
{'horse and the hound and the horn', 'belonged to'}
14+
}
15+
16+
verse = (n) ->
17+
things = ["the #{data[i][1]} that #{data[i][2]}" for i = n, 1, -1]
18+
'This is ' .. table.concat things, ' '
19+
20+
{
21+
recite: (start, stop) ->
22+
[verse n for n = start, stop]
23+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
string_list = (list, level) ->
2+
if #list <= 2
3+
"{#{table.concat [quote elem for elem in *list], ', '}}"
4+
else
5+
instrs = [indent quote(elem) .. ',', level + 1 for elem in *list]
6+
table.insert instrs, 1, '{'
7+
table.insert instrs, indent('}', level)
8+
table.concat instrs, '\n'
9+
10+
{
11+
module_name: 'House',
12+
13+
generate_test: (case, level) ->
14+
lines = {
15+
"result = House.#{case.property} #{case.input.startVerse}, #{case.input.endVerse}",
16+
"expected = #{string_list case.expected, level}",
17+
"assert.are.same expected, result"
18+
}
19+
table.concat [indent line, level for line in *lines], '\n'
20+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
[28a540ff-f765-4348-9d57-ae33f25f41f2]
13+
description = "verse one - the house that jack built"
14+
15+
[ebc825ac-6e2b-4a5e-9afd-95732191c8da]
16+
description = "verse two - the malt that lay"
17+
18+
[1ed8bb0f-edb8-4bd1-b6d4-b64754fe4a60]
19+
description = "verse three - the rat that ate"
20+
21+
[64b0954e-8b7d-4d14-aad0-d3f6ce297a30]
22+
description = "verse four - the cat that killed"
23+
24+
[1e8d56bc-fe31-424d-9084-61e6111d2c82]
25+
description = "verse five - the dog that worried"
26+
27+
[6312dc6f-ab0a-40c9-8a55-8d4e582beac4]
28+
description = "verse six - the cow with the crumpled horn"
29+
30+
[68f76d18-6e19-4692-819c-5ff6a7f92feb]
31+
description = "verse seven - the maiden all forlorn"
32+
33+
[73872564-2004-4071-b51d-2e4326096747]
34+
description = "verse eight - the man all tattered and torn"
35+
36+
[0d53d743-66cb-4351-a173-82702f3338c9]
37+
description = "verse nine - the priest all shaven and shorn"
38+
39+
[452f24dc-8fd7-4a82-be1a-3b4839cfeb41]
40+
description = "verse 10 - the rooster that crowed in the morn"
41+
42+
[97176f20-2dd3-4646-ac72-cffced91ea26]
43+
description = "verse 11 - the farmer sowing his corn"
44+
45+
[09824c29-6aad-4dcd-ac98-f61374a6a8b7]
46+
description = "verse 12 - the horse and the hound and the horn"
47+
48+
[d2b980d3-7851-49e1-97ab-1524515ec200]
49+
description = "multiple verses"
50+
51+
[0311d1d0-e085-4f23-8ae7-92406fb3e803]
52+
description = "full rhyme"
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: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
House = require 'house'
2+
3+
describe 'house', ->
4+
it 'verse one - the house that jack built', ->
5+
result = House.recite 1, 1
6+
expected = {'This is the house that Jack built.'}
7+
assert.are.same expected, result
8+
9+
pending 'verse two - the malt that lay', ->
10+
result = House.recite 2, 2
11+
expected = {'This is the malt that lay in the house that Jack built.'}
12+
assert.are.same expected, result
13+
14+
pending 'verse three - the rat that ate', ->
15+
result = House.recite 3, 3
16+
expected = {'This is the rat that ate the malt that lay in the house that Jack built.'}
17+
assert.are.same expected, result
18+
19+
pending 'verse four - the cat that killed', ->
20+
result = House.recite 4, 4
21+
expected = {'This is the cat that killed the rat that ate the malt that lay in the house that Jack built.'}
22+
assert.are.same expected, result
23+
24+
pending 'verse five - the dog that worried', ->
25+
result = House.recite 5, 5
26+
expected = {'This is the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.'}
27+
assert.are.same expected, result
28+
29+
pending 'verse six - the cow with the crumpled horn', ->
30+
result = House.recite 6, 6
31+
expected = {'This is the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.'}
32+
assert.are.same expected, result
33+
34+
pending 'verse seven - the maiden all forlorn', ->
35+
result = House.recite 7, 7
36+
expected = {'This is the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.'}
37+
assert.are.same expected, result
38+
39+
pending 'verse eight - the man all tattered and torn', ->
40+
result = House.recite 8, 8
41+
expected = {'This is the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.'}
42+
assert.are.same expected, result
43+
44+
pending 'verse nine - the priest all shaven and shorn', ->
45+
result = House.recite 9, 9
46+
expected = {'This is the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.'}
47+
assert.are.same expected, result
48+
49+
pending 'verse 10 - the rooster that crowed in the morn', ->
50+
result = House.recite 10, 10
51+
expected = {'This is the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.'}
52+
assert.are.same expected, result
53+
54+
pending 'verse 11 - the farmer sowing his corn', ->
55+
result = House.recite 11, 11
56+
expected = {'This is the farmer sowing his corn that kept the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.'}
57+
assert.are.same expected, result
58+
59+
pending 'verse 12 - the horse and the hound and the horn', ->
60+
result = House.recite 12, 12
61+
expected = {'This is the horse and the hound and the horn that belonged to the farmer sowing his corn that kept the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.'}
62+
assert.are.same expected, result
63+
64+
pending 'multiple verses', ->
65+
result = House.recite 4, 8
66+
expected = {
67+
'This is the cat that killed the rat that ate the malt that lay in the house that Jack built.',
68+
'This is the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.',
69+
'This is the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.',
70+
'This is the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.',
71+
'This is the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.',
72+
}
73+
assert.are.same expected, result
74+
75+
pending 'full rhyme', ->
76+
result = House.recite 1, 12
77+
expected = {
78+
'This is the house that Jack built.',
79+
'This is the malt that lay in the house that Jack built.',
80+
'This is the rat that ate the malt that lay in the house that Jack built.',
81+
'This is the cat that killed the rat that ate the malt that lay in the house that Jack built.',
82+
'This is the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.',
83+
'This is the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.',
84+
'This is the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.',
85+
'This is the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.',
86+
'This is the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.',
87+
'This is the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.',
88+
'This is the farmer sowing his corn that kept the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.',
89+
'This is the horse and the hound and the horn that belonged to the farmer sowing his corn that kept the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.',
90+
}
91+
assert.are.same expected, result

0 commit comments

Comments
 (0)