diff --git a/config.json b/config.json index be183d8..8ae0766 100644 --- a/config.json +++ b/config.json @@ -282,6 +282,14 @@ "prerequisites": [], "difficulty": 3 }, + { + "slug": "house", + "name": "House", + "uuid": "60a9a9e9-0b19-40cd-8d4c-d8f3af092d55", + "practices": [], + "prerequisites": [], + "difficulty": 3 + }, { "slug": "matrix", "name": "Matrix", diff --git a/exercises/practice/house/.busted b/exercises/practice/house/.busted new file mode 100644 index 0000000..86b84e7 --- /dev/null +++ b/exercises/practice/house/.busted @@ -0,0 +1,5 @@ +return { + default = { + ROOT = { '.' } + } +} diff --git a/exercises/practice/house/.docs/instructions.md b/exercises/practice/house/.docs/instructions.md new file mode 100644 index 0000000..88928c5 --- /dev/null +++ b/exercises/practice/house/.docs/instructions.md @@ -0,0 +1,105 @@ +# Instructions + +Recite 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][papyr] + +The nursery rhyme reads as follows: + +```text +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. +``` + +[papyr]: https://papyr.com/hypertextbooks/grammar/ph_noun.htm diff --git a/exercises/practice/house/.meta/config.json b/exercises/practice/house/.meta/config.json new file mode 100644 index 0000000..868df4b --- /dev/null +++ b/exercises/practice/house/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "glennj" + ], + "files": { + "solution": [ + "house.moon" + ], + "test": [ + "house_spec.moon" + ], + "example": [ + ".meta/example.moon" + ] + }, + "blurb": "Output the nursery rhyme 'This is the House that Jack Built'.", + "source": "British nursery rhyme", + "source_url": "https://en.wikipedia.org/wiki/This_Is_The_House_That_Jack_Built" +} diff --git a/exercises/practice/house/.meta/example.moon b/exercises/practice/house/.meta/example.moon new file mode 100644 index 0000000..6861be4 --- /dev/null +++ b/exercises/practice/house/.meta/example.moon @@ -0,0 +1,23 @@ +data = { + {'house', 'Jack built.'} + {'malt', 'lay in'} + {'rat', 'ate'} + {'cat', 'killed'} + {'dog', 'worried'} + {'cow with the crumpled horn', 'tossed'} + {'maiden all forlorn', 'milked'} + {'man all tattered and torn', 'kissed'} + {'priest all shaven and shorn', 'married'} + {'rooster that crowed in the morn', 'woke'} + {'farmer sowing his corn', 'kept'} + {'horse and the hound and the horn', 'belonged to'} +} + +verse = (n) -> + things = ["the #{data[i][1]} that #{data[i][2]}" for i = n, 1, -1] + 'This is ' .. table.concat things, ' ' + +{ + recite: (start, stop) -> + [verse n for n = start, stop] +} diff --git a/exercises/practice/house/.meta/spec_generator.moon b/exercises/practice/house/.meta/spec_generator.moon new file mode 100644 index 0000000..d7b6d7e --- /dev/null +++ b/exercises/practice/house/.meta/spec_generator.moon @@ -0,0 +1,20 @@ +string_list = (list, level) -> + if #list <= 2 + "{#{table.concat [quote elem for elem in *list], ', '}}" + else + instrs = [indent quote(elem) .. ',', level + 1 for elem in *list] + table.insert instrs, 1, '{' + table.insert instrs, indent('}', level) + table.concat instrs, '\n' + +{ + module_name: 'House', + + generate_test: (case, level) -> + lines = { + "result = House.#{case.property} #{case.input.startVerse}, #{case.input.endVerse}", + "expected = #{string_list case.expected, level}", + "assert.are.same expected, result" + } + table.concat [indent line, level for line in *lines], '\n' +} diff --git a/exercises/practice/house/.meta/tests.toml b/exercises/practice/house/.meta/tests.toml new file mode 100644 index 0000000..da24dc3 --- /dev/null +++ b/exercises/practice/house/.meta/tests.toml @@ -0,0 +1,52 @@ +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[28a540ff-f765-4348-9d57-ae33f25f41f2] +description = "verse one - the house that jack built" + +[ebc825ac-6e2b-4a5e-9afd-95732191c8da] +description = "verse two - the malt that lay" + +[1ed8bb0f-edb8-4bd1-b6d4-b64754fe4a60] +description = "verse three - the rat that ate" + +[64b0954e-8b7d-4d14-aad0-d3f6ce297a30] +description = "verse four - the cat that killed" + +[1e8d56bc-fe31-424d-9084-61e6111d2c82] +description = "verse five - the dog that worried" + +[6312dc6f-ab0a-40c9-8a55-8d4e582beac4] +description = "verse six - the cow with the crumpled horn" + +[68f76d18-6e19-4692-819c-5ff6a7f92feb] +description = "verse seven - the maiden all forlorn" + +[73872564-2004-4071-b51d-2e4326096747] +description = "verse eight - the man all tattered and torn" + +[0d53d743-66cb-4351-a173-82702f3338c9] +description = "verse nine - the priest all shaven and shorn" + +[452f24dc-8fd7-4a82-be1a-3b4839cfeb41] +description = "verse 10 - the rooster that crowed in the morn" + +[97176f20-2dd3-4646-ac72-cffced91ea26] +description = "verse 11 - the farmer sowing his corn" + +[09824c29-6aad-4dcd-ac98-f61374a6a8b7] +description = "verse 12 - the horse and the hound and the horn" + +[d2b980d3-7851-49e1-97ab-1524515ec200] +description = "multiple verses" + +[0311d1d0-e085-4f23-8ae7-92406fb3e803] +description = "full rhyme" diff --git a/exercises/practice/house/house.moon b/exercises/practice/house/house.moon new file mode 100644 index 0000000..32aaa7b --- /dev/null +++ b/exercises/practice/house/house.moon @@ -0,0 +1,4 @@ +{ + recite: (start, stop) -> + error 'Implement me' +} diff --git a/exercises/practice/house/house_spec.moon b/exercises/practice/house/house_spec.moon new file mode 100644 index 0000000..bcf5028 --- /dev/null +++ b/exercises/practice/house/house_spec.moon @@ -0,0 +1,91 @@ +House = require 'house' + +describe 'house', -> + it 'verse one - the house that jack built', -> + result = House.recite 1, 1 + expected = {'This is the house that Jack built.'} + assert.are.same expected, result + + pending 'verse two - the malt that lay', -> + result = House.recite 2, 2 + expected = {'This is the malt that lay in the house that Jack built.'} + assert.are.same expected, result + + pending 'verse three - the rat that ate', -> + result = House.recite 3, 3 + expected = {'This is the rat that ate the malt that lay in the house that Jack built.'} + assert.are.same expected, result + + pending 'verse four - the cat that killed', -> + result = House.recite 4, 4 + expected = {'This is the cat that killed the rat that ate the malt that lay in the house that Jack built.'} + assert.are.same expected, result + + pending 'verse five - the dog that worried', -> + result = House.recite 5, 5 + 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.'} + assert.are.same expected, result + + pending 'verse six - the cow with the crumpled horn', -> + result = House.recite 6, 6 + 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.'} + assert.are.same expected, result + + pending 'verse seven - the maiden all forlorn', -> + result = House.recite 7, 7 + 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.'} + assert.are.same expected, result + + pending 'verse eight - the man all tattered and torn', -> + result = House.recite 8, 8 + 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.'} + assert.are.same expected, result + + pending 'verse nine - the priest all shaven and shorn', -> + result = House.recite 9, 9 + 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.'} + assert.are.same expected, result + + pending 'verse 10 - the rooster that crowed in the morn', -> + result = House.recite 10, 10 + 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.'} + assert.are.same expected, result + + pending 'verse 11 - the farmer sowing his corn', -> + result = House.recite 11, 11 + 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.'} + assert.are.same expected, result + + pending 'verse 12 - the horse and the hound and the horn', -> + result = House.recite 12, 12 + 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.'} + assert.are.same expected, result + + pending 'multiple verses', -> + result = House.recite 4, 8 + expected = { + '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.', + } + assert.are.same expected, result + + pending 'full rhyme', -> + result = House.recite 1, 12 + expected = { + '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.', + } + assert.are.same expected, result