Skip to content

Commit d55c830

Browse files
authored
Merge pull request exercism#709 from Smarticles101/house-implement
house: add to track
2 parents e476e79 + 194b319 commit d55c830

7 files changed

Lines changed: 549 additions & 0 deletions

File tree

config.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,16 @@
442442

443443
]
444444
},
445+
{
446+
"uuid": "6b51aca3-3451-4a64-ad7b-00b151d7548a",
447+
"slug": "house",
448+
"core": false,
449+
"unlocked_by": null,
450+
"difficulty": 6,
451+
"topics": [
452+
453+
]
454+
},
445455
{
446456
"uuid": "dd3e6fd6-5359-4978-acd7-c39374cead4d",
447457
"slug": "food-chain",

exercises/house/README.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# House
2+
3+
Output the nursery rhyme 'This is the House that Jack Built'.
4+
5+
> [The] process of placing a phrase of clause within another phrase of
6+
> clause is called embedding. It is through the processes of recursion
7+
> and embedding that we are able to take a finite number of forms (words
8+
> and phrases) and construct an infinite number of expressions.
9+
> Furthermore, embedding also allows us to construct an infinitely long
10+
> structure, in theory anyway.
11+
12+
- [papyr.com](http://papyr.com/hypertextbooks/grammar/ph_noun.htm)
13+
14+
15+
The nursery rhyme reads as follows:
16+
17+
```plain
18+
This is the house that Jack built.
19+
20+
This is the malt
21+
that lay in the house that Jack built.
22+
23+
This is the rat
24+
that ate the malt
25+
that lay in the house that Jack built.
26+
27+
This is the cat
28+
that killed the rat
29+
that ate the malt
30+
that lay in the house that Jack built.
31+
32+
This is the dog
33+
that worried the cat
34+
that killed the rat
35+
that ate the malt
36+
that lay in the house that Jack built.
37+
38+
This is the cow with the crumpled horn
39+
that tossed the dog
40+
that worried the cat
41+
that killed the rat
42+
that ate the malt
43+
that lay in the house that Jack built.
44+
45+
This is the maiden all forlorn
46+
that milked the cow with the crumpled horn
47+
that tossed the dog
48+
that worried the cat
49+
that killed the rat
50+
that ate the malt
51+
that lay in the house that Jack built.
52+
53+
This is the man all tattered and torn
54+
that kissed the maiden all forlorn
55+
that milked the cow with the crumpled horn
56+
that tossed the dog
57+
that worried the cat
58+
that killed the rat
59+
that ate the malt
60+
that lay in the house that Jack built.
61+
62+
This is the priest all shaven and shorn
63+
that married the man all tattered and torn
64+
that kissed the maiden all forlorn
65+
that milked the cow with the crumpled horn
66+
that tossed the dog
67+
that worried the cat
68+
that killed the rat
69+
that ate the malt
70+
that lay in the house that Jack built.
71+
72+
This is the rooster that crowed in the morn
73+
that woke the priest all shaven and shorn
74+
that married the man all tattered and torn
75+
that kissed the maiden all forlorn
76+
that milked the cow with the crumpled horn
77+
that tossed the dog
78+
that worried the cat
79+
that killed the rat
80+
that ate the malt
81+
that lay in the house that Jack built.
82+
83+
This is the farmer sowing his corn
84+
that kept the rooster that crowed in the morn
85+
that woke the priest all shaven and shorn
86+
that married the man all tattered and torn
87+
that kissed the maiden all forlorn
88+
that milked the cow with the crumpled horn
89+
that tossed the dog
90+
that worried the cat
91+
that killed the rat
92+
that ate the malt
93+
that lay in the house that Jack built.
94+
95+
This is the horse and the hound and the horn
96+
that belonged to the farmer sowing his corn
97+
that kept the rooster that crowed in the morn
98+
that woke the priest all shaven and shorn
99+
that married the man all tattered and torn
100+
that kissed the maiden all forlorn
101+
that milked the cow with the crumpled horn
102+
that tossed the dog
103+
that worried the cat
104+
that killed the rat
105+
that ate the malt
106+
that lay in the house that Jack built.
107+
```
108+
109+
110+
To run the tests:
111+
112+
```sh
113+
$ gradle test
114+
```
115+
116+
For more detailed info about the Java track see the [help page](http://exercism.io/languages/java).
117+
118+
119+
## Source
120+
121+
British nursery rhyme [http://en.wikipedia.org/wiki/This_Is_The_House_That_Jack_Built](http://en.wikipedia.org/wiki/This_Is_The_House_That_Jack_Built)
122+
123+
## Submitting Incomplete Solutions
124+
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

exercises/house/build.gradle

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apply plugin: "java"
2+
apply plugin: "eclipse"
3+
apply plugin: "idea"
4+
5+
repositories {
6+
mavenCentral()
7+
}
8+
9+
dependencies {
10+
testCompile "junit:junit:4.12"
11+
}
12+
13+
test {
14+
testLogging {
15+
exceptionFormat = 'full'
16+
events = ["passed", "failed", "skipped"]
17+
}
18+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
class House {
2+
private static final String[] CHARACTERS = {
3+
"house that Jack built.",
4+
"malt",
5+
"rat",
6+
"cat",
7+
"dog",
8+
"cow with the crumpled horn",
9+
"maiden all forlorn",
10+
"man all tattered and torn",
11+
"priest all shaven and shorn",
12+
"rooster that crowed in the morn",
13+
"farmer sowing his corn",
14+
"horse and the hound and the horn"
15+
};
16+
17+
private static final String[] ACTIONS = {
18+
"lay in",
19+
"ate",
20+
"killed",
21+
"worried",
22+
"tossed",
23+
"milked",
24+
"kissed",
25+
"married",
26+
"woke",
27+
"kept",
28+
"belonged to"
29+
};
30+
31+
String verse(int verseNumber) {
32+
StringBuilder verse = new StringBuilder();
33+
verse.append("This is the " + CHARACTERS[verseNumber - 1]);
34+
35+
for (int i = verseNumber - 2; i >= 0; i--) {
36+
verse.append("\nthat " + ACTIONS[i] + " the " + CHARACTERS[i]);
37+
}
38+
39+
return verse.toString();
40+
}
41+
42+
String verses(int startVerse, int endVerse) {
43+
String[] verses = new String[endVerse - startVerse + 1];
44+
45+
for (int i = startVerse; i <= endVerse; i++) {
46+
verses[i - startVerse] = verse(i);
47+
}
48+
49+
return String.join("\n\n", verses);
50+
}
51+
52+
String sing() {
53+
return verses(1, 12);
54+
}
55+
}

exercises/house/src/main/java/.keep

Whitespace-only changes.

0 commit comments

Comments
 (0)