Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,16 @@

]
},
{
"uuid": "6b51aca3-3451-4a64-ad7b-00b151d7548a",
"slug": "house",
"core": false,
"unlocked_by": null,
"difficulty": 6,
"topics": [

]
},
{
"uuid": "dd3e6fd6-5359-4978-acd7-c39374cead4d",
"slug": "food-chain",
Expand Down
124 changes: 124 additions & 0 deletions exercises/house/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# House

Output the nursery rhyme 'This is the House that Jack Built'.

> [The] process of placing a phrase of clause within another phrase of
> clause is called embedding. 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.
> Furthermore, embedding also allows us to construct an infinitely long
> structure, in theory anyway.

- [papyr.com](http://papyr.com/hypertextbooks/grammar/ph_noun.htm)


The nursery rhyme reads as follows:

```plain
This is the house that Jack built.

This is the malt
that lay in the house that Jack built.

This is the rat
that ate the malt
that lay in the house that Jack built.

This is the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.

This is the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.

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.

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.

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.

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.

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.

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.

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.
```


To run the tests:

```sh
$ gradle test
```

For more detailed info about the Java track see the [help page](http://exercism.io/languages/java).


## Source

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)

## Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
18 changes: 18 additions & 0 deletions exercises/house/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apply plugin: "java"
apply plugin: "eclipse"
apply plugin: "idea"

repositories {
mavenCentral()
}

dependencies {
testCompile "junit:junit:4.12"
}

test {
testLogging {
exceptionFormat = 'full'
events = ["passed", "failed", "skipped"]
}
}
55 changes: 55 additions & 0 deletions exercises/house/src/example/java/House.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
class House {
private static final String[] CHARACTERS = {
"house that Jack built.",
"malt",
"rat",
"cat",
"dog",
"cow with the crumpled horn",
"maiden all forlorn",
"man all tattered and torn",
"priest all shaven and shorn",
"rooster that crowed in the morn",
"farmer sowing his corn",
"horse and the hound and the horn"
};

private static final String[] ACTIONS = {
"lay in",
"ate",
"killed",
"worried",
"tossed",
"milked",
"kissed",
"married",
"woke",
"kept",
"belonged to"
};

String verse(int verseNumber) {
StringBuilder verse = new StringBuilder();
verse.append("This is the " + CHARACTERS[verseNumber - 1]);

for (int i = verseNumber - 2; i >= 0; i--) {
verse.append("\nthat " + ACTIONS[i] + " the " + CHARACTERS[i]);
}

return verse.toString();
}

String verses(int startVerse, int endVerse) {
String[] verses = new String[endVerse - startVerse + 1];

for (int i = startVerse; i <= endVerse; i++) {
verses[i - startVerse] = verse(i);
}

return String.join("\n\n", verses);
}

String sing() {
return verses(1, 12);
}
}
Empty file.
Loading