Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New Exercise]: Proverb #238

Merged
merged 4 commits into from
Aug 2, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,14 @@
"prerequisites": [],
"difficulty": 2
},
{
"slug": "proverb",
"name": "Proverb",
"uuid": "f44f56dd-5220-4304-9214-e02b159868e6",
"practices": [],
"prerequisites": [],
"difficulty": 2
},
{
"slug": "matrix",
"name": "Matrix",
Expand Down
19 changes: 19 additions & 0 deletions exercises/practice/proverb/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -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.
38 changes: 38 additions & 0 deletions exercises/practice/proverb/.meta/Proverb.example.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Function Get-Proverb() {
<#
.SYNOPSIS
Given a list of inputs, generate the relevant proverb.

.DESCRIPTION
Take a list of inputs and output the full text of a proverbial rhyme base on those inputs.

.PARAMETER Data
The list of inputs to generate the proverb.

.EXAMPLE
Get-Proverb -Data @("nail", "shoe", "horse", "rider", "message", "battle", "kingdom")

@"
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.
"@
#>
[CmdletBinding()]
Param(
[string[]]$Data
)
if (-not $Data.Count) {
return ""
}
$Proverb = @()
for ($i = 0; $i -lt $Data.Count - 1; $i++) {
$Proverb += "For want of a $($Data[$i]) the $($Data[$i+1]) was lost."
}
$Proverb += "And all for the want of a $($Data[0])."
return $Proverb -join "`r`n"
}
17 changes: 17 additions & 0 deletions exercises/practice/proverb/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"authors": ["glaxxie"],
"files": {
"solution": [
"Proverb.ps1"
],
"test": [
"Proverb.tests.ps1"
],
"example": [
".meta/Proverb.example.ps1"
]
},
"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"
}
28 changes: 28 additions & 0 deletions exercises/practice/proverb/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -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"
30 changes: 30 additions & 0 deletions exercises/practice/proverb/Proverb.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Function Get-Proverb() {
<#
.SYNOPSIS
Given a list of inputs, generate the relevant proverb.

.DESCRIPTION
Take a list of inputs and output the full text of a proverbial rhyme base on those inputs.

.PARAMETER Data
The list of inputs to generate the proverb.

.EXAMPLE
Get-Proverb -Data @("nail", "shoe", "horse", "rider", "message", "battle", "kingdom")

@"
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.
"@
#>
[CmdletBinding()]
Param(
[string[]]$Data
)
Throw "Please implement this function."
}
59 changes: 59 additions & 0 deletions exercises/practice/proverb/Proverb.tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
BeforeAll {
. "./Proverb.ps1"
}

Describe "Test Get-Proverb" {
It "zero pieces" {
$got = Get-Proverb -Data @()
$want = ""

$got | Should -BeExactly $want
}

It "one piece" {
$got = Get-Proverb -Data @("nail")
$want = "And all for the want of a nail."

$got | Should -BeExactly $want
}

It "two pieces" {
$got = Get-Proverb -Data @("nail", "shoe")
$want = ( "For want of a nail the shoe was lost.",
"And all for the want of a nail.") -join "`r`n"

$got | Should -BeExactly $want
}

It "three pieces" {
$got = Get-Proverb -Data @("nail", "shoe", "horse")
$want = ( "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.") -join "`r`n"

$got | Should -BeExactly $want
}

It "full proverb" {
$got = Get-Proverb -Data @("nail", "shoe", "horse", "rider", "message", "battle", "kingdom")
$want = ( "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.") -join "`r`n"

$got | Should -BeExactly $want
}

It "four pieces modernized" {
$got = Get-Proverb -Data @("pin", "gun", "soldier", "battle")
$want = ( "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.") -join "`r`n"

$got | Should -BeExactly $want
}
}