From a9be501aff5ff2f8d8072b586ba28b37faff6450 Mon Sep 17 00:00:00 2001 From: Ronaldo Ferreira de Lima Date: Thu, 31 Jul 2025 00:40:11 -0300 Subject: [PATCH 1/4] * add new practice exercise: acronym --- config.json | 8 ++++ .../practice/acronym/.docs/instructions.md | 17 ++++++++ exercises/practice/acronym/.meta/config.json | 19 +++++++++ exercises/practice/acronym/.meta/example.sql | 20 ++++++++++ exercises/practice/acronym/.meta/tests.toml | 37 +++++++++++++++++ exercises/practice/acronym/acronym.sql | 2 + exercises/practice/acronym/acronym_test.sql | 40 +++++++++++++++++++ exercises/practice/acronym/create_fixture.sql | 10 +++++ .../practice/acronym/create_test_table.sql | 29 ++++++++++++++ exercises/practice/acronym/data.csv | 9 +++++ 10 files changed, 191 insertions(+) create mode 100644 exercises/practice/acronym/.docs/instructions.md create mode 100644 exercises/practice/acronym/.meta/config.json create mode 100644 exercises/practice/acronym/.meta/example.sql create mode 100644 exercises/practice/acronym/.meta/tests.toml create mode 100644 exercises/practice/acronym/acronym.sql create mode 100644 exercises/practice/acronym/acronym_test.sql create mode 100644 exercises/practice/acronym/create_fixture.sql create mode 100644 exercises/practice/acronym/create_test_table.sql create mode 100644 exercises/practice/acronym/data.csv diff --git a/config.json b/config.json index 1084ab0..865fd0c 100644 --- a/config.json +++ b/config.json @@ -186,6 +186,14 @@ "prerequisites": [], "difficulty": 7 }, + { + "slug": "acronym", + "name": "Acronym", + "uuid": "880388be-1e77-4092-bcf3-f237572c40e1", + "practices": [], + "prerequisites": [], + "difficulty": 7 + }, { "slug": "armstrong-numbers", "name": "Armstrong Numbers", 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..458dfab --- /dev/null +++ b/exercises/practice/acronym/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "jimmytty" + ], + "files": { + "solution": [ + "acronym.sql" + ], + "test": [ + "acronym_test.sql" + ], + "example": [ + ".meta/example.sql" + ] + }, + "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.sql b/exercises/practice/acronym/.meta/example.sql new file mode 100644 index 0000000..a26eb24 --- /dev/null +++ b/exercises/practice/acronym/.meta/example.sql @@ -0,0 +1,20 @@ +UPDATE acronym + SET result = ( + WITH RECURSIVE + rcte(string, abbr) AS ( + VALUES(' ' || phrase, '') + UNION ALL + SELECT + SUBSTR(string,2), + abbr || + CASE + WHEN GLOB('[ _-]', SUBSTR(string, 1, 1)) + AND GLOB('[A-Za-z]', SUBSTR(string, 2, 1)) + THEN SUBSTR(string, 2, 1) + ELSE '' + END + FROM rcte + WHERE string GLOB '*[ _-]*' + ) + SELECT UPPER(abbr) FROM rcte WHERE string NOT GLOB '*[ _-]*' + ); 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.sql b/exercises/practice/acronym/acronym.sql new file mode 100644 index 0000000..9dfe741 --- /dev/null +++ b/exercises/practice/acronym/acronym.sql @@ -0,0 +1,2 @@ +-- Schema: CREATE TABLE acronym ( phrase TEXT PRIMARY KEY, result TEXT ); +-- Task: update the acronym table and set the result based on the phrase. diff --git a/exercises/practice/acronym/acronym_test.sql b/exercises/practice/acronym/acronym_test.sql new file mode 100644 index 0000000..caa841f --- /dev/null +++ b/exercises/practice/acronym/acronym_test.sql @@ -0,0 +1,40 @@ +-- Create database: +.read ./create_fixture.sql + +-- Read user student solution and save any output as markdown in user_output.md: +.mode markdown +.output user_output.md +.read ./acronym.sql +.output + +-- Create a clean testing environment: +.read ./create_test_table.sql + +-- Comparison of user input and the tests updates the status for each test: +UPDATE tests +SET status = 'pass' +FROM (SELECT phrase, result FROM acronym) AS actual +WHERE (actual.phrase, actual.result) = (tests.phrase, tests.expected); + +-- Update message for failed tests to give helpful information: +UPDATE tests +SET message = ( + 'Result for "' + || tests.phrase + || '"' + || ' is <' || COALESCE(actual.result, 'NULL') + || '> but should be <' || tests.expected || '>' +) +FROM (SELECT phrase, result FROM acronym) AS actual +WHERE actual.phrase = tests.phrase AND tests.status = 'fail'; + +-- Save results to ./output.json (needed by the online test-runner) +.mode json +.once './output.json' +SELECT description, status, message, output, test_code, task_id +FROM tests; + +-- Display test results in readable form for the student: +.mode table +SELECT description, status, message +FROM tests; diff --git a/exercises/practice/acronym/create_fixture.sql b/exercises/practice/acronym/create_fixture.sql new file mode 100644 index 0000000..a521328 --- /dev/null +++ b/exercises/practice/acronym/create_fixture.sql @@ -0,0 +1,10 @@ +DROP TABLE IF EXISTS acronym; +CREATE TABLE acronym ( + phrase TEXT PRIMARY KEY, + result TEXT +); + +-- Note: the CSV file may contain literal tab, newline, carriage returns. + +.mode csv +.import ./data.csv acronym diff --git a/exercises/practice/acronym/create_test_table.sql b/exercises/practice/acronym/create_test_table.sql new file mode 100644 index 0000000..d4bf791 --- /dev/null +++ b/exercises/practice/acronym/create_test_table.sql @@ -0,0 +1,29 @@ +DROP TABLE IF EXISTS tests; +CREATE TABLE IF NOT EXISTS tests ( + -- uuid and description are taken from the test.toml file + uuid TEXT PRIMARY KEY, + description TEXT NOT NULL, + -- The following section is needed by the online test-runner + status TEXT DEFAULT 'fail', + message TEXT, + output TEXT, + test_code TEXT, + task_id INTEGER DEFAULT NULL, + -- Here are columns for the actual tests + phrase TEXT NOT NULL, + expected TEXT NOT NULL +); + +-- Note: the strings below _may_ contain literal tab, newline, or carriage returns. + +INSERT INTO tests (uuid, description, phrase, expected) +VALUES + ('1e22cceb-c5e4-4562-9afe-aef07ad1eaf4','basic','Portable Network Graphics','PNG'), + ('79ae3889-a5c0-4b01-baf0-232d31180c08','lowercase words','Ruby on Rails','ROR'), + ('ec7000a7-3931-4a17-890e-33ca2073a548','punctuation','First In, First Out','FIFO'), + ('32dd261c-0c92-469a-9c5c-b192e94a63b0','all caps word','GNU Image Manipulation Program','GIMP'), + ('ae2ac9fa-a606-4d05-8244-3bcc4659c1d4','punctuation without whitespace','Complementary metal-oxide semiconductor','CMOS'), + ('0e4b1e7c-1a6d-48fb-81a7-bf65eb9e69f9','very long abbreviation','Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me','ROTFLSHTMDCOALM'), + ('6a078f49-c68d-4b7b-89af-33a1a98c28cc','consecutive delimiters','Something - I made up from thin air','SIMUFTA'), + ('5118b4b1-4572-434c-8d57-5b762e57973e','apostrophes','Halley''s Comet','HC'), + ('adc12eab-ec2d-414f-b48c-66a4fc06cdef','underscore emphasis','The Road _Not_ Taken','TRNT'); diff --git a/exercises/practice/acronym/data.csv b/exercises/practice/acronym/data.csv new file mode 100644 index 0000000..c7d935a --- /dev/null +++ b/exercises/practice/acronym/data.csv @@ -0,0 +1,9 @@ +"Portable Network Graphics","" +"Ruby on Rails","" +"First In, First Out","" +"GNU Image Manipulation Program","" +"Complementary metal-oxide semiconductor","" +"Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me","" +"Something - I made up from thin air","" +"Halley's Comet","" +"The Road _Not_ Taken","" From b02043b6e413cb02effc66517111924868ea5f6f Mon Sep 17 00:00:00 2001 From: Ronaldo Ferreira de Lima Date: Thu, 31 Jul 2025 09:06:54 -0300 Subject: [PATCH 2/4] * normalizing the difficulty to 8 --- config.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/config.json b/config.json index 9190578..8f3add4 100644 --- a/config.json +++ b/config.json @@ -194,14 +194,6 @@ "prerequisites": [], "difficulty": 7 }, - { - "slug": "acronym", - "name": "Acronym", - "uuid": "880388be-1e77-4092-bcf3-f237572c40e1", - "practices": [], - "prerequisites": [], - "difficulty": 7 - }, { "slug": "armstrong-numbers", "name": "Armstrong Numbers", @@ -273,6 +265,14 @@ "practices": [], "prerequisites": [], "difficulty": 8 + }, + { + "slug": "acronym", + "name": "Acronym", + "uuid": "880388be-1e77-4092-bcf3-f237572c40e1", + "practices": [], + "prerequisites": [], + "difficulty": 8 } ] }, From 4defd92146aa713fb06bd5ddbbe872b96505d0f3 Mon Sep 17 00:00:00 2001 From: Ronaldo Ferreira de Lima Date: Thu, 31 Jul 2025 09:15:00 -0300 Subject: [PATCH 3/4] * removing unnecessary comments --- exercises/practice/acronym/create_fixture.sql | 2 -- exercises/practice/acronym/create_test_table.sql | 2 -- 2 files changed, 4 deletions(-) diff --git a/exercises/practice/acronym/create_fixture.sql b/exercises/practice/acronym/create_fixture.sql index a521328..7c706ee 100644 --- a/exercises/practice/acronym/create_fixture.sql +++ b/exercises/practice/acronym/create_fixture.sql @@ -4,7 +4,5 @@ CREATE TABLE acronym ( result TEXT ); --- Note: the CSV file may contain literal tab, newline, carriage returns. - .mode csv .import ./data.csv acronym diff --git a/exercises/practice/acronym/create_test_table.sql b/exercises/practice/acronym/create_test_table.sql index d4bf791..e717ea8 100644 --- a/exercises/practice/acronym/create_test_table.sql +++ b/exercises/practice/acronym/create_test_table.sql @@ -14,8 +14,6 @@ CREATE TABLE IF NOT EXISTS tests ( expected TEXT NOT NULL ); --- Note: the strings below _may_ contain literal tab, newline, or carriage returns. - INSERT INTO tests (uuid, description, phrase, expected) VALUES ('1e22cceb-c5e4-4562-9afe-aef07ad1eaf4','basic','Portable Network Graphics','PNG'), From 42643712e42cd669f57a602078763c9383cb58e2 Mon Sep 17 00:00:00 2001 From: Ronaldo Ferreira de Lima Date: Thu, 31 Jul 2025 19:09:49 -0300 Subject: [PATCH 4/4] * sort by difficulty then slug --- config.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/config.json b/config.json index 8f3add4..6057fd6 100644 --- a/config.json +++ b/config.json @@ -194,6 +194,14 @@ "prerequisites": [], "difficulty": 7 }, + { + "slug": "acronym", + "name": "Acronym", + "uuid": "880388be-1e77-4092-bcf3-f237572c40e1", + "practices": [], + "prerequisites": [], + "difficulty": 8 + }, { "slug": "armstrong-numbers", "name": "Armstrong Numbers", @@ -265,14 +273,6 @@ "practices": [], "prerequisites": [], "difficulty": 8 - }, - { - "slug": "acronym", - "name": "Acronym", - "uuid": "880388be-1e77-4092-bcf3-f237572c40e1", - "practices": [], - "prerequisites": [], - "difficulty": 8 } ] },