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 #233

Merged
merged 1 commit into from
Apr 3, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,14 @@
"practices": [],
"prerequisites": [],
"difficulty": 2
},
{
"slug": "acronym",
"name": "Acronym",
"uuid": "8a470aa6-6a54-4a37-83a8-f86c35f6b567",
"practices": [],
"prerequisites": [],
"difficulty": 2
}
]
},
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 |
22 changes: 22 additions & 0 deletions exercises/practice/acronym/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"authors": [
"BNAndras"
],
"contributors": [
"BethanyG"
],
"files": {
"solution": [
"source/acronym.d"
],
"test": [
"source/acronym.d"
],
"example": [
"example/acronym.d"
]
},
"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"
2 changes: 2 additions & 0 deletions exercises/practice/acronym/dub.sdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name "acronym"
buildRequirements "disallowDeprecations"
11 changes: 11 additions & 0 deletions exercises/practice/acronym/example/acronym.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module acronym;

import std.regex;
import std.string;

immutable r = regex(r"(?<!_)\B[\w']+|[\W_]");

string abbreviate(immutable string phrase)
{
return replaceAll(phrase.toUpper(), r, "");
}
69 changes: 69 additions & 0 deletions exercises/practice/acronym/source/acronym.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
module acronym;

string abbreviate(immutable string phrase)
{
// implement this function
}

unittest
{
immutable int allTestsEnabled = 0;

// Basic abbreviation
{
string phrase = "Portable Network Graphics";
assert(abbreviate(phrase) == "PNG");
}

static if (allTestsEnabled)
{

// Lowercase words
{
string phrase = "Ruby on Rails";
assert(abbreviate(phrase) == "ROR");
}

// Punctuation
{
string phrase = "First In, First Out";
assert(abbreviate(phrase) == "FIFO");
}

// All caps word
{
string phrase = "GNU Image Manipulation Program";
assert(abbreviate(phrase) == "GIMP");
}

// punctuation without whitespace
{
string phrase = "Complementary metal-oxide semiconductor";
assert(abbreviate(phrase) == "CMOS");
}

// Very long abbreviation
{
string phrase = "Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me";
assert(abbreviate(phrase) == "ROTFLSHTMDCOALM");
}

// Consecutive delimiters
{
string phrase = "Something - I made up from thin air";
assert(abbreviate(phrase) == "SIMUFTA");
}

// Apostrophes
{
string phrase = "Halley's Comet";
assert(abbreviate(phrase) == "HC");
}

// Underscore emphasis
{
string phrase = "The Road _Not_ Taken";
assert(abbreviate(phrase) == "TRNT");
}
}
}