diff --git a/config.json b/config.json index 3b6da20..a42fea9 100644 --- a/config.json +++ b/config.json @@ -432,6 +432,14 @@ "prerequisites": [], "difficulty": 3 }, + { + "slug": "proverb", + "name": "Proverb", + "uuid": "4df0877e-d97a-401a-8b73-bfa8f7cb5e4a", + "practices": [], + "prerequisites": [], + "difficulty": 3 + }, { "slug": "pythagorean-triplet", "name": "Pythagorean Triplet", diff --git a/exercises/practice/proverb/.docs/instructions.md b/exercises/practice/proverb/.docs/instructions.md new file mode 100644 index 0000000..f6fb859 --- /dev/null +++ b/exercises/practice/proverb/.docs/instructions.md @@ -0,0 +1,19 @@ +# Instructions + +For want of a horseshoe nail, a kingdom was lost, or so the saying goes. + +Given a list of inputs, generate the relevant proverb. +For example, given the list `["nail", "shoe", "horse", "rider", "message", "battle", "kingdom"]`, you will output the full text of this proverbial rhyme: + +```text +For want of a nail the shoe was lost. +For want of a shoe the horse was lost. +For want of a horse the rider was lost. +For want of a rider the message was lost. +For want of a message the battle was lost. +For want of a battle the kingdom was lost. +And all for the want of a nail. +``` + +Note that the list of inputs may vary; your solution should be able to handle lists of arbitrary length and content. +No line of the output text should be a static, unchanging string; all should vary according to the input given. diff --git a/exercises/practice/proverb/.meta/config.json b/exercises/practice/proverb/.meta/config.json new file mode 100644 index 0000000..9477906 --- /dev/null +++ b/exercises/practice/proverb/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "keiravillekode" + ], + "files": { + "solution": [ + "proverb.wren" + ], + "test": [ + "proverb.spec.wren" + ], + "example": [ + ".meta/proof.ci.wren" + ] + }, + "blurb": "For want of a horseshoe nail, a kingdom was lost, or so the saying goes. Output the full text of this proverbial rhyme.", + "source": "Wikipedia", + "source_url": "https://en.wikipedia.org/wiki/For_Want_of_a_Nail" +} diff --git a/exercises/practice/proverb/.meta/proof.ci.wren b/exercises/practice/proverb/.meta/proof.ci.wren new file mode 100644 index 0000000..6ca4d42 --- /dev/null +++ b/exercises/practice/proverb/.meta/proof.ci.wren @@ -0,0 +1,15 @@ +class Proverb { + static recite(strings) { + var result = [] + for (index in 0...strings.count) { + var line = null + if (index + 1 < strings.count) { + line = "For want of a %(strings[index]) the %(strings[index + 1]) was lost." + } else { + line = "And all for the want of a %(strings[0])." + } + result.add(line) + } + return result + } +} diff --git a/exercises/practice/proverb/.meta/tests.toml b/exercises/practice/proverb/.meta/tests.toml new file mode 100644 index 0000000..dc92a0c --- /dev/null +++ b/exercises/practice/proverb/.meta/tests.toml @@ -0,0 +1,28 @@ +# 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. + +[e974b73e-7851-484f-8d6d-92e07fe742fc] +description = "zero pieces" + +[2fcd5f5e-8b82-4e74-b51d-df28a5e0faa4] +description = "one piece" + +[d9d0a8a1-d933-46e2-aa94-eecf679f4b0e] +description = "two pieces" + +[c95ef757-5e94-4f0d-a6cb-d2083f5e5a83] +description = "three pieces" + +[433fb91c-35a2-4d41-aeab-4de1e82b2126] +description = "full proverb" + +[c1eefa5a-e8d9-41c7-91d4-99fab6d6b9f7] +description = "four pieces modernized" diff --git a/exercises/practice/proverb/LICENSE b/exercises/practice/proverb/LICENSE new file mode 100644 index 0000000..c362f61 --- /dev/null +++ b/exercises/practice/proverb/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Exercism + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/exercises/practice/proverb/package.wren b/exercises/practice/proverb/package.wren new file mode 100644 index 0000000..794f071 --- /dev/null +++ b/exercises/practice/proverb/package.wren @@ -0,0 +1,14 @@ +import "wren-package" for WrenPackage, Dependency +import "os" for Process + +class Package is WrenPackage { + construct new() {} + name { "exercism/proverb" } + dependencies { + return [ + Dependency.new("wren-testie", "0.3.0", "https://github.com/joshgoebel/wren-testie.git") + ] + } +} + +Package.new().default() diff --git a/exercises/practice/proverb/proverb.spec.wren b/exercises/practice/proverb/proverb.spec.wren new file mode 100644 index 0000000..85e60a5 --- /dev/null +++ b/exercises/practice/proverb/proverb.spec.wren @@ -0,0 +1,86 @@ +import "./proverb" for Proverb +import "wren-testie/testie" for Testie, Expect + +Testie.test("Proverb") { |do, skip| + do.test("zero pieces") { + var strings = [ + ] + var expected = [ + ] + Expect.value(Proverb.recite(strings)).toEqual(expected) + } + + skip.test("one piece") { + var strings = [ + "nail", + ] + var expected = [ + "And all for the want of a nail.", + ] + Expect.value(Proverb.recite(strings)).toEqual(expected) + } + + skip.test("two pieces") { + var strings = [ + "nail", + "shoe", + ] + var expected = [ + "For want of a nail the shoe was lost.", + "And all for the want of a nail.", + ] + Expect.value(Proverb.recite(strings)).toEqual(expected) + } + + skip.test("three pieces") { + var strings = [ + "nail", + "shoe", + "horse", + ] + var expected = [ + "For want of a nail the shoe was lost.", + "For want of a shoe the horse was lost.", + "And all for the want of a nail.", + ] + Expect.value(Proverb.recite(strings)).toEqual(expected) + } + + skip.test("full proverb") { + var strings = [ + "nail", + "shoe", + "horse", + "rider", + "message", + "battle", + "kingdom", + ] + var expected = [ + "For want of a nail the shoe was lost.", + "For want of a shoe the horse was lost.", + "For want of a horse the rider was lost.", + "For want of a rider the message was lost.", + "For want of a message the battle was lost.", + "For want of a battle the kingdom was lost.", + "And all for the want of a nail.", + ] + Expect.value(Proverb.recite(strings)).toEqual(expected) + } + + skip.test("four pieces modernized") { + var strings = [ + "pin", + "gun", + "soldier", + "battle", + ] + var expected = [ + "For want of a pin the gun was lost.", + "For want of a gun the soldier was lost.", + "For want of a soldier the battle was lost.", + "And all for the want of a pin.", + ] + Expect.value(Proverb.recite(strings)).toEqual(expected) + } +} diff --git a/exercises/practice/proverb/proverb.wren b/exercises/practice/proverb/proverb.wren new file mode 100644 index 0000000..0f03396 --- /dev/null +++ b/exercises/practice/proverb/proverb.wren @@ -0,0 +1,5 @@ +class Proverb { + static recite(strings) { + Fiber.abort("Remove this statement and implement this function") + } +}