diff --git a/config.json b/config.json index 7933d6b..3166d2a 100644 --- a/config.json +++ b/config.json @@ -133,6 +133,14 @@ "practices": [], "prerequisites": [], "difficulty": 5 + }, + { + "slug": "acronym", + "name": "Acronym", + "uuid": "16ede285-40d5-4df8-a582-f35b4d121d3c", + "practices": [], + "prerequisites": [], + "difficulty": 3 } ] }, diff --git a/exercises/practice/acronym/.docs/instructions.md b/exercises/practice/acronym/.docs/instructions.md new file mode 100644 index 0000000..133bd2c --- /dev/null +++ b/exercises/practice/acronym/.docs/instructions.md @@ -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 | diff --git a/exercises/practice/acronym/.meta/config.json b/exercises/practice/acronym/.meta/config.json new file mode 100644 index 0000000..37975f3 --- /dev/null +++ b/exercises/practice/acronym/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "quintuple-mallard" + ], + "files": { + "solution": [ + "acronym.nu" + ], + "test": [ + "tests.nu" + ], + "example": [ + ".meta/example.nu" + ] + }, + "blurb": "Convert a long phrase to its acronym.", + "source": "Julien Vanier", + "source_url": "https://github.com/monkbroc" +} diff --git a/exercises/practice/acronym/.meta/example.nu b/exercises/practice/acronym/.meta/example.nu new file mode 100644 index 0000000..2be0215 --- /dev/null +++ b/exercises/practice/acronym/.meta/example.nu @@ -0,0 +1,14 @@ +def alphabetic [c: string] { + let c = $c | str downcase + $c >= a and $c <= z +} +export def abbreviate [phrase: string] { + $phrase + | split chars + | where (alphabetic $it) or $it in " -" + | str join + | split row -r "[ -]" + | each {|w| $w | split chars | first} + | str join + | str upcase +} diff --git a/exercises/practice/acronym/.meta/tests.toml b/exercises/practice/acronym/.meta/tests.toml new file mode 100644 index 0000000..6e3277c --- /dev/null +++ b/exercises/practice/acronym/.meta/tests.toml @@ -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" diff --git a/exercises/practice/acronym/acronym.nu b/exercises/practice/acronym/acronym.nu new file mode 100644 index 0000000..824b84d --- /dev/null +++ b/exercises/practice/acronym/acronym.nu @@ -0,0 +1,3 @@ +export def abbreviate [phrase: string] { + error make {msg: "Please implement abbreviate"} +} diff --git a/exercises/practice/acronym/tests.nu b/exercises/practice/acronym/tests.nu new file mode 100644 index 0000000..34784f0 --- /dev/null +++ b/exercises/practice/acronym/tests.nu @@ -0,0 +1,11 @@ +use acronym.nu abbreviate +use std/assert +assert equal (abbreviate "Portable Network Graphics") "PNG" +assert equal (abbreviate "Ruby on Rails") "ROR" +assert equal (abbreviate "First In, First Out") "FIFO" +assert equal (abbreviate "GNU Image Manipulation Program") "GIMP" +assert equal (abbreviate "Complementary metal-oxide semiconductor") "CMOS" +assert equal (abbreviate "Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me") "ROTFLSHTMDCOALM" +assert equal (abbreviate "Something - I made up from thin air") "SIMUFTA" +assert equal (abbreviate "Halley's Comet") "HC" +assert equal (abbreviate "The Road _Not_ Taken") "TRNT"