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

Add Acronym #229

Merged
merged 2 commits into from
Jul 23, 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
36 changes: 23 additions & 13 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@
"strings"
]
},
{
"slug": "collatz-conjecture",
"name": "Collatz Conjecture",
"uuid": "39447c38-8509-45fb-9070-3ff6be50c0d5",
"practices": [],
"prerequisites": [],
"difficulty": 1,
"topics": [
"errors",
"control_flow_if_else_statements",
"integers"
]
},
{
"slug": "resistor-color",
"name": "Resistor Color",
Expand Down Expand Up @@ -351,6 +364,16 @@
"prerequisites": [],
"difficulty": 2
},
{
"slug": "acronym",
"name": "Acronym",
"uuid": "84e522fc-d042-43fe-8dd2-84c9f1150d1e",
"practices": [
"regular-expressions"
],
"prerequisites": [],
"difficulty": 2
},
{
"slug": "nth-prime",
"name": "Nth Prime",
Expand All @@ -360,19 +383,6 @@
],
"prerequisites": [],
"difficulty": 3
},
{
"slug": "collatz-conjecture",
"name": "Collatz Conjecture",
"uuid": "39447c38-8509-45fb-9070-3ff6be50c0d5",
"practices": [],
"prerequisites": [],
"difficulty": 1,
"topics": [
"errors",
"control_flow_if_else_statements",
"integers"
]
}
]
},
Expand Down
17 changes: 17 additions & 0 deletions exercises/practice/acronym/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Instructions

Convert a phrase to its acronym.

Techies love their TLA (Three Letter Acronyms)!

Help generate some jargon by writing a program that converts a long name like Portable Network Graphics to its acronym (PNG).

Punctuation is handled as follows: hyphens are word separators (like whitespace); all other punctuation can be removed from the input.

For example:

|Input|Output|
|-|-|
|As Soon As Possible|ASAP|
|Liquid-crystal display|LCD|
|Thank George It's Friday!|TGIF|
21 changes: 21 additions & 0 deletions exercises/practice/acronym/.meta/Acronym.example.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Function Get-Acronym() {
<#
.SYNOPSIS
Get the acronym of a phrase.

.DESCRIPTION
Given a phrase, return the string acronym of that phrase.
"As Soon As Possible" => "ASAP"

.PARAMETER Phrase
The phrase to get the acronym from.

.EXAMPLE
Get-Acronym -Phrase "As Soon As Possible"
#>
[CmdletBinding()]
Param (
[string]$Phrase
)
return ([regex]::Matches($Phrase, "\p{L}+'?\p{L}*") | ForEach-Object { $_.Value[0] }) -join ""
}
17 changes: 17 additions & 0 deletions exercises/practice/acronym/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"authors": ["glaxxie"],
"files": {
"solution": [
"Acronym.ps1"
],
"test": [
"Acronym.tests.ps1"
],
"example": [
".meta/Acronym.example.ps1"
]
},
"blurb": "Convert a long phrase to its acronym.",
"source": "Julien Vanier",
"source_url": "https://github.com/monkbroc"
}
37 changes: 37 additions & 0 deletions exercises/practice/acronym/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 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.

[1e22cceb-c5e4-4562-9afe-aef07ad1eaf4]
description = "basic"

[79ae3889-a5c0-4b01-baf0-232d31180c08]
description = "lowercase words"

[ec7000a7-3931-4a17-890e-33ca2073a548]
description = "punctuation"

[32dd261c-0c92-469a-9c5c-b192e94a63b0]
description = "all caps word"

[ae2ac9fa-a606-4d05-8244-3bcc4659c1d4]
description = "punctuation without whitespace"

[0e4b1e7c-1a6d-48fb-81a7-bf65eb9e69f9]
description = "very long abbreviation"

[6a078f49-c68d-4b7b-89af-33a1a98c28cc]
description = "consecutive delimiters"

[5118b4b1-4572-434c-8d57-5b762e57973e]
description = "apostrophes"

[adc12eab-ec2d-414f-b48c-66a4fc06cdef]
description = "underscore emphasis"
21 changes: 21 additions & 0 deletions exercises/practice/acronym/Acronym.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Function Get-Acronym() {
<#
.SYNOPSIS
Get the acronym of a phrase.

.DESCRIPTION
Given a phrase, return the string acronym of that phrase.
"As Soon As Possible" => "ASAP"

.PARAMETER Phrase
The phrase to get the acronym from.

.EXAMPLE
Get-Acronym -Phrase "As Soon As Possible"
#>
[CmdletBinding()]
Param (
[string]$Phrase
)
Throw "Please implement this function"
}
59 changes: 59 additions & 0 deletions exercises/practice/acronym/Acronym.tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
BeforeAll {
. ".\Acronym.ps1"
}

Describe "AcronymTests" {
It "basic" {
$got = Get-Acronym -Phrase "Portable Networks Graphic"
$want = "PNG"
$got | Should -Be $want
}

It "lowercase words" {
$got = Get-Acronym -Phrase "Ruby on Rails"
$want = "ROR"
$got | Should -Be $want
}

It "punctuation" {
$got = Get-Acronym -Phrase "First in, First out"
$want = "FIFO"
$got | Should -Be $want
}

It "all caps word" {
$got = Get-Acronym -Phrase "GNU Image Manipulation Program"
$want = "GIMP"
$got | Should -Be $want
}

It "punctuation without whitespace" {
$got = Get-Acronym -Phrase "Complementary Metal-Oxide semiconductor"
$want = "CMOS"
$got | Should -Be $want
}

It "very long abbreviation" {
$got = Get-Acronym -Phrase "Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me"
$want = "ROTFLSHTMDCOALM"
$got | Should -Be $want
}

It "consecutive delimiters" {
$got = Get-Acronym -Phrase "Something - I made up from thin air"
$want = "SIMUFTA"
$got | Should -Be $want
}

It "apostrophes" {
$got = Get-Acronym -Phrase "Halley's Comet"
$want = "HC"
$got | Should -Be $want
}

It "underscore emphasis" {
$got = Get-Acronym -Phrase "The Road _Not_ Taken"
$want = "TRNT"
$got | Should -Be $want
}
}