From 3fde7f9550c7fb0beb4b7a756e42caf69bc28b77 Mon Sep 17 00:00:00 2001 From: habere-et-dispertire Date: Wed, 11 Dec 2024 22:53:54 +0000 Subject: [PATCH 1/8] Updated config.json --- config.json | 8 ++++ .../practice/proverb/.docs/instructions.md | 19 ++++++++ exercises/practice/proverb/.meta/config.json | 19 ++++++++ .../.meta/solutions/lib/Proverb.rakumod | 15 ++++++ .../.meta/solutions/t/proverb.rakutest | 1 + .../practice/proverb/.meta/template-data.yaml | 33 +++++++++++++ exercises/practice/proverb/.meta/tests.toml | 28 +++++++++++ .../practice/proverb/lib/Proverb.rakumod | 5 ++ exercises/practice/proverb/t/proverb.rakutest | 48 +++++++++++++++++++ 9 files changed, 176 insertions(+) create mode 100644 exercises/practice/proverb/.docs/instructions.md create mode 100644 exercises/practice/proverb/.meta/config.json create mode 100644 exercises/practice/proverb/.meta/solutions/lib/Proverb.rakumod create mode 120000 exercises/practice/proverb/.meta/solutions/t/proverb.rakutest create mode 100644 exercises/practice/proverb/.meta/template-data.yaml create mode 100644 exercises/practice/proverb/.meta/tests.toml create mode 100644 exercises/practice/proverb/lib/Proverb.rakumod create mode 100755 exercises/practice/proverb/t/proverb.rakutest diff --git a/config.json b/config.json index 38b9a735..5e5ef8d4 100644 --- a/config.json +++ b/config.json @@ -735,6 +735,14 @@ "practices": [], "prerequisites": [], "difficulty": 1 + }, + { + "slug": "proverb", + "name": "Proverb", + "uuid": "ef243fad-2ac8-4313-a484-1c28a6d7ab21", + "practices": [], + "prerequisites": [], + "difficulty": 1 } ] }, diff --git a/exercises/practice/proverb/.docs/instructions.md b/exercises/practice/proverb/.docs/instructions.md new file mode 100644 index 00000000..f6fb8593 --- /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 00000000..962abc34 --- /dev/null +++ b/exercises/practice/proverb/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "habere-et-dispertire" + ], + "files": { + "solution": [ + "lib/Proverb.rakumod" + ], + "test": [ + "t/proverb.rakutest" + ], + "example": [ + ".meta/solutions/lib/Proverb.rakumod" + ] + }, + "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/solutions/lib/Proverb.rakumod b/exercises/practice/proverb/.meta/solutions/lib/Proverb.rakumod new file mode 100644 index 00000000..1e205c82 --- /dev/null +++ b/exercises/practice/proverb/.meta/solutions/lib/Proverb.rakumod @@ -0,0 +1,15 @@ +unit module Proverb; + +sub recite (*@nouns --> Str()) is export { + given @nouns.elems { + when 0 { Empty } + when 1 { "And all for the want of a {@nouns.head}." } + default { + join "\n", + @nouns + .rotor(2=>-1) + .map( { "For want of a {.head} the {.tail} was lost." } ), + recite @nouns.head + } + } +} diff --git a/exercises/practice/proverb/.meta/solutions/t/proverb.rakutest b/exercises/practice/proverb/.meta/solutions/t/proverb.rakutest new file mode 120000 index 00000000..7b98c3b9 --- /dev/null +++ b/exercises/practice/proverb/.meta/solutions/t/proverb.rakutest @@ -0,0 +1 @@ +../../../t/proverb.rakutest \ No newline at end of file diff --git a/exercises/practice/proverb/.meta/template-data.yaml b/exercises/practice/proverb/.meta/template-data.yaml new file mode 100644 index 00000000..f83e9614 --- /dev/null +++ b/exercises/practice/proverb/.meta/template-data.yaml @@ -0,0 +1,33 @@ +properties: + recite: + test: |- + sprintf(q :to 'END', %case.Array.raku, %case.join("\n").raku, %case.raku); + cmp-ok( + recite(%s), + "eq", + %s, + %s, + ); + END + + +unit: module +example: |- + sub recite (*@nouns --> Str()) is export { + given @nouns.elems { + when 0 { Empty } + when 1 { "And all for the want of a {@nouns.head}." } + default { + join "\n", + @nouns + .rotor(2=>-1) + .map( { "For want of a {.head} the {.tail} was lost." } ), + recite @nouns.head + } + } + } + +stub: |- + sub recite (*@nouns --> Str()) is export { + ... + } diff --git a/exercises/practice/proverb/.meta/tests.toml b/exercises/practice/proverb/.meta/tests.toml new file mode 100644 index 00000000..dc92a0c9 --- /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/lib/Proverb.rakumod b/exercises/practice/proverb/lib/Proverb.rakumod new file mode 100644 index 00000000..133502f8 --- /dev/null +++ b/exercises/practice/proverb/lib/Proverb.rakumod @@ -0,0 +1,5 @@ +unit module Proverb; + +sub recite (*@nouns --> Str()) is export { + ... +} diff --git a/exercises/practice/proverb/t/proverb.rakutest b/exercises/practice/proverb/t/proverb.rakutest new file mode 100755 index 00000000..1bedca1a --- /dev/null +++ b/exercises/practice/proverb/t/proverb.rakutest @@ -0,0 +1,48 @@ +#!/usr/bin/env raku +use Test; +use lib $?FILE.IO.parent(2).add('lib'); +use Proverb; + +cmp-ok( # begin: e974b73e-7851-484f-8d6d-92e07fe742fc + recite([]), + "eq", + "", + "zero pieces", +); # end: e974b73e-7851-484f-8d6d-92e07fe742fc + +cmp-ok( # begin: 2fcd5f5e-8b82-4e74-b51d-df28a5e0faa4 + recite(["nail"]), + "eq", + "And all for the want of a nail.", + "one piece", +); # end: 2fcd5f5e-8b82-4e74-b51d-df28a5e0faa4 + +cmp-ok( # begin: d9d0a8a1-d933-46e2-aa94-eecf679f4b0e + recite(["nail", "shoe"]), + "eq", + "For want of a nail the shoe was lost.\nAnd all for the want of a nail.", + "two pieces", +); # end: d9d0a8a1-d933-46e2-aa94-eecf679f4b0e + +cmp-ok( # begin: c95ef757-5e94-4f0d-a6cb-d2083f5e5a83 + recite(["nail", "shoe", "horse"]), + "eq", + "For want of a nail the shoe was lost.\nFor want of a shoe the horse was lost.\nAnd all for the want of a nail.", + "three pieces", +); # end: c95ef757-5e94-4f0d-a6cb-d2083f5e5a83 + +cmp-ok( # begin: 433fb91c-35a2-4d41-aeab-4de1e82b2126 + recite(["nail", "shoe", "horse", "rider", "message", "battle", "kingdom"]), + "eq", + "For want of a nail the shoe was lost.\nFor want of a shoe the horse was lost.\nFor want of a horse the rider was lost.\nFor want of a rider the message was lost.\nFor want of a message the battle was lost.\nFor want of a battle the kingdom was lost.\nAnd all for the want of a nail.", + "full proverb", +); # end: 433fb91c-35a2-4d41-aeab-4de1e82b2126 + +cmp-ok( # begin: c1eefa5a-e8d9-41c7-91d4-99fab6d6b9f7 + recite(["pin", "gun", "soldier", "battle"]), + "eq", + "For want of a pin the gun was lost.\nFor want of a gun the soldier was lost.\nFor want of a soldier the battle was lost.\nAnd all for the want of a pin.", + "four pieces modernized", +); # end: c1eefa5a-e8d9-41c7-91d4-99fab6d6b9f7 + +done-testing; From 86370cc10a5e95473b496b47cfd2cef3d78a0d6c Mon Sep 17 00:00:00 2001 From: habere-et-dispertire Date: Thu, 12 Dec 2024 19:48:23 +0000 Subject: [PATCH 2/8] Encourage a multi-dispatch approach --- .../.meta/solutions/lib/Proverb.rakumod | 22 +++++++-------- .../practice/proverb/.meta/template-data.yaml | 27 ++++++++++--------- .../practice/proverb/lib/Proverb.rakumod | 5 +++- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/exercises/practice/proverb/.meta/solutions/lib/Proverb.rakumod b/exercises/practice/proverb/.meta/solutions/lib/Proverb.rakumod index 1e205c82..64d7cf72 100644 --- a/exercises/practice/proverb/.meta/solutions/lib/Proverb.rakumod +++ b/exercises/practice/proverb/.meta/solutions/lib/Proverb.rakumod @@ -1,15 +1,13 @@ unit module Proverb; -sub recite (*@nouns --> Str()) is export { - given @nouns.elems { - when 0 { Empty } - when 1 { "And all for the want of a {@nouns.head}." } - default { - join "\n", - @nouns - .rotor(2=>-1) - .map( { "For want of a {.head} the {.tail} was lost." } ), - recite @nouns.head - } - } +multi recite ( $noun where $_ eq '' ) is export { } +multi recite ( $noun where $_ ne '' ) { + "And all for the want of a $noun." +} +multi recite ( @nouns ) { + join "\n", + @nouns + .rotor(2=>-1) + .map( { "For want of a {.head} the {.tail} was lost." } ), + recite @nouns.head } diff --git a/exercises/practice/proverb/.meta/template-data.yaml b/exercises/practice/proverb/.meta/template-data.yaml index f83e9614..c2cd5609 100644 --- a/exercises/practice/proverb/.meta/template-data.yaml +++ b/exercises/practice/proverb/.meta/template-data.yaml @@ -13,21 +13,22 @@ properties: unit: module example: |- - sub recite (*@nouns --> Str()) is export { - given @nouns.elems { - when 0 { Empty } - when 1 { "And all for the want of a {@nouns.head}." } - default { - join "\n", - @nouns - .rotor(2=>-1) - .map( { "For want of a {.head} the {.tail} was lost." } ), - recite @nouns.head - } - } + multi recite ( $noun where $_ eq '' ) is export { } + multi recite ( $noun where $_ ne '' ) { + "And all for the want of a $noun." + } + multi recite ( @nouns ) { + join "\n", + @nouns + .rotor(2=>-1) + .map( { "For want of a {.head} the {.tail} was lost." } ), + recite @nouns.head } stub: |- - sub recite (*@nouns --> Str()) is export { + multi recite ($nouns) is export { + ... + } + multi recite (@nouns) is export { ... } diff --git a/exercises/practice/proverb/lib/Proverb.rakumod b/exercises/practice/proverb/lib/Proverb.rakumod index 133502f8..037c66cd 100644 --- a/exercises/practice/proverb/lib/Proverb.rakumod +++ b/exercises/practice/proverb/lib/Proverb.rakumod @@ -1,5 +1,8 @@ unit module Proverb; -sub recite (*@nouns --> Str()) is export { +multi recite ($nouns) is export { + ... +} +multi recite (@nouns) is export { ... } From 8d854170a7dab0aa373aa959c0f1472b98877e8f Mon Sep 17 00:00:00 2001 From: habere-et-dispertire Date: Wed, 18 Dec 2024 20:40:31 +0000 Subject: [PATCH 3/8] Revert stub to sub --- exercises/practice/proverb/.DS_Store | Bin 0 -> 6148 bytes .../practice/proverb/.meta/template-data.yaml | 6 +----- exercises/practice/proverb/lib/Proverb.rakumod | 6 +----- 3 files changed, 2 insertions(+), 10 deletions(-) create mode 100644 exercises/practice/proverb/.DS_Store diff --git a/exercises/practice/proverb/.DS_Store b/exercises/practice/proverb/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..90c7b22c90821be20ca3d7dadb1b9b842af1c415 GIT binary patch literal 6148 zcmeH~JqiLr422W55Nx)zoW=uqgF*BJUO-k61i?b==jgutu;6MfA}^4ET z-rJ!i>uPEXjdsx-J~ZE~HpRd++C>XCFs&{OBtQZq0@K)ccK+|+pXUEj3%4Xd0)Iw8 zXWRXDgOAFy_3iU4f5@z@8yxE82rriaZ0smr!rkz^*aBKpTPQLxUIZKi0||VUz!L$j B5n})V literal 0 HcmV?d00001 diff --git a/exercises/practice/proverb/.meta/template-data.yaml b/exercises/practice/proverb/.meta/template-data.yaml index c2cd5609..db54d937 100644 --- a/exercises/practice/proverb/.meta/template-data.yaml +++ b/exercises/practice/proverb/.meta/template-data.yaml @@ -26,9 +26,5 @@ example: |- } stub: |- - multi recite ($nouns) is export { - ... - } - multi recite (@nouns) is export { - ... + sub proverb (@nouns) is export { } diff --git a/exercises/practice/proverb/lib/Proverb.rakumod b/exercises/practice/proverb/lib/Proverb.rakumod index 037c66cd..61202808 100644 --- a/exercises/practice/proverb/lib/Proverb.rakumod +++ b/exercises/practice/proverb/lib/Proverb.rakumod @@ -1,8 +1,4 @@ unit module Proverb; -multi recite ($nouns) is export { - ... -} -multi recite (@nouns) is export { - ... +sub proverb (@nouns) is export { } From 51f7b05328105e34987b0b08ce576ff4f7d46053 Mon Sep 17 00:00:00 2001 From: habere-et-dispertire Date: Sun, 22 Dec 2024 10:55:03 +0000 Subject: [PATCH 4/8] Delete .DS_Store --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index f58ada30..88cb4968 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ bin/configlet bin/configlet.exe # dir created when a Raku module is used .precomp +.DS_Store + From f3d6199b4081a163eb7966a62ee2049e418655d6 Mon Sep 17 00:00:00 2001 From: habere-et-dispertire Date: Sun, 22 Dec 2024 10:59:10 +0000 Subject: [PATCH 5/8] Delete .gitignore x2 --- .gitignore | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 88cb4968..00000000 --- a/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -.problem-specifications -bin/configlet -bin/configlet.exe -# dir created when a Raku module is used -.precomp -.DS_Store - From 610cb8c4093307ee2af6fe95a714346d65e8dbca Mon Sep 17 00:00:00 2001 From: habere-et-dispertire Date: Sun, 22 Dec 2024 11:50:13 +0000 Subject: [PATCH 6/8] Revert "Delete .gitignore x2" This reverts commit f3d6199b4081a163eb7966a62ee2049e418655d6. --- .gitignore | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..88cb4968 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +.problem-specifications +bin/configlet +bin/configlet.exe +# dir created when a Raku module is used +.precomp +.DS_Store + From 89415edb949b2132fb62ef277edd9d9834ee6418 Mon Sep 17 00:00:00 2001 From: habere-et-dispertire Date: Sun, 22 Dec 2024 11:50:19 +0000 Subject: [PATCH 7/8] Revert "Delete .DS_Store" This reverts commit 51f7b05328105e34987b0b08ce576ff4f7d46053. --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index 88cb4968..f58ada30 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,3 @@ bin/configlet bin/configlet.exe # dir created when a Raku module is used .precomp -.DS_Store - From 510b3391529d841dda6b481a08a6c79b38943ff4 Mon Sep 17 00:00:00 2001 From: habere-et-dispertire Date: Sun, 22 Dec 2024 11:53:44 +0000 Subject: [PATCH 8/8] Delete .DS_Store (try #3) --- exercises/practice/proverb/.DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 exercises/practice/proverb/.DS_Store diff --git a/exercises/practice/proverb/.DS_Store b/exercises/practice/proverb/.DS_Store deleted file mode 100644 index 90c7b22c90821be20ca3d7dadb1b9b842af1c415..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~JqiLr422W55Nx)zoW=uqgF*BJUO-k61i?b==jgutu;6MfA}^4ET z-rJ!i>uPEXjdsx-J~ZE~HpRd++C>XCFs&{OBtQZq0@K)ccK+|+pXUEj3%4Xd0)Iw8 zXWRXDgOAFy_3iU4f5@z@8yxE82rriaZ0smr!rkz^*aBKpTPQLxUIZKi0||VUz!L$j B5n})V