-
-
Notifications
You must be signed in to change notification settings - Fork 15
Acronym: add new practice exercise #102
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a9be501
* add new practice exercise: acronym
jimmytty deb81c8
Merge branch 'main' into acronym
jimmytty b02043b
* normalizing the difficulty to 8
jimmytty 4defd92
* removing unnecessary comments
jimmytty 4264371
* sort by difficulty then slug
jimmytty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 '*[ _-]*' | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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. | ||
|
jimmytty marked this conversation as resolved.
Outdated
|
||
|
|
||
| .mode csv | ||
| .import ./data.csv acronym | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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. | ||
|
jimmytty marked this conversation as resolved.
Outdated
|
||
|
|
||
| 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'); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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","" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.