Skip to content

Commit 245971e

Browse files
authored
Add new practice exercise: reverse-string (#108)
1 parent 031ecb1 commit 245971e

File tree

11 files changed

+178
-0
lines changed

11 files changed

+178
-0
lines changed

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,14 @@
290290
"prerequisites": [],
291291
"difficulty": 8
292292
},
293+
{
294+
"slug": "reverse-string",
295+
"name": "Reverse String",
296+
"uuid": "cf1c3ed8-167a-47e8-af1a-2cc2d8403525",
297+
"practices": [],
298+
"prerequisites": [],
299+
"difficulty": 8
300+
},
293301
{
294302
"slug": "roman-numerals",
295303
"name": "Roman Numerals",
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Instructions
2+
3+
Your task is to reverse a given string.
4+
5+
Some examples:
6+
7+
- Turn `"stressed"` into `"desserts"`.
8+
- Turn `"strops"` into `"sports"`.
9+
- Turn `"racecar"` into `"racecar"`.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Introduction
2+
3+
Reversing strings (reading them from right to left, rather than from left to right) is a surprisingly common task in programming.
4+
5+
For example, in bioinformatics, reversing the sequence of DNA or RNA strings is often important for various analyses, such as finding complementary strands or identifying palindromic sequences that have biological significance.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"authors": [
3+
"jimmytty"
4+
],
5+
"files": {
6+
"solution": [
7+
"reverse-string.sql"
8+
],
9+
"test": [
10+
"reverse-string_test.sql"
11+
],
12+
"example": [
13+
".meta/example.sql"
14+
]
15+
},
16+
"blurb": "Reverse a given string.",
17+
"source": "Introductory challenge to reverse an input string",
18+
"source_url": "https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb"
19+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
UPDATE "reverse-string"
2+
SET result = (
3+
WITH RECURSIVE reverse_char(string, char) AS (
4+
VALUES(input, '')
5+
UNION ALL
6+
SELECT SUBSTRING(string, 1, LENGTH(string) - 1),
7+
SUBSTRING(string, -1)
8+
FROM reverse_char
9+
WHERE string <> ''
10+
) SELECT GROUP_CONCAT(char, '') FROM reverse_char
11+
);
12+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
11+
12+
[c3b7d806-dced-49ee-8543-933fd1719b1c]
13+
description = "an empty string"
14+
15+
[01ebf55b-bebb-414e-9dec-06f7bb0bee3c]
16+
description = "a word"
17+
18+
[0f7c07e4-efd1-4aaa-a07a-90b49ce0b746]
19+
description = "a capitalized word"
20+
21+
[71854b9c-f200-4469-9f5c-1e8e5eff5614]
22+
description = "a sentence with punctuation"
23+
24+
[1f8ed2f3-56f3-459b-8f3e-6d8d654a1f6c]
25+
description = "a palindrome"
26+
27+
[b9e7dec1-c6df-40bd-9fa3-cd7ded010c4c]
28+
description = "an even-sized word"
29+
30+
[1bed0f8a-13b0-4bd3-9d59-3d0593326fa2]
31+
description = "wide characters"
32+
include = false
33+
comment = "skip unicode scenarios"
34+
35+
[93d7e1b8-f60f-4f3c-9559-4056e10d2ead]
36+
description = "grapheme cluster with pre-combined form"
37+
include = false
38+
comment = "skip unicode scenarios"
39+
40+
[1028b2c1-6763-4459-8540-2da47ca512d9]
41+
description = "grapheme clusters"
42+
include = false
43+
comment = "skip unicode scenarios"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
DROP TABLE IF EXISTS "reverse-string";
2+
CREATE TABLE "reverse-string" (
3+
input TEXT NOT NULL,
4+
result TEXT
5+
);
6+
7+
.mode csv
8+
.import ./data.csv reverse-string
9+
10+
UPDATE "reverse-string" SET result = NULL;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
DROP TABLE IF EXISTS tests;
2+
CREATE TABLE IF NOT EXISTS tests (
3+
-- uuid and description are taken from the test.toml file
4+
uuid TEXT PRIMARY KEY,
5+
description TEXT NOT NULL,
6+
-- The following section is needed by the online test-runner
7+
status TEXT DEFAULT 'fail',
8+
message TEXT,
9+
output TEXT,
10+
test_code TEXT,
11+
task_id INTEGER DEFAULT NULL,
12+
-- Here are columns for the actual tests
13+
input TEXT NOT NULL,
14+
expected TEXT NOT NULL
15+
);
16+
17+
INSERT INTO tests (uuid, description, input, expected)
18+
VALUES
19+
('c3b7d806-dced-49ee-8543-933fd1719b1c','an empty string','',''),
20+
('01ebf55b-bebb-414e-9dec-06f7bb0bee3c','a word','robot','tobor'),
21+
('0f7c07e4-efd1-4aaa-a07a-90b49ce0b746','a capitalized word','Ramen','nemaR'),
22+
('71854b9c-f200-4469-9f5c-1e8e5eff5614','a sentence with punctuation','I''m hungry!','!yrgnuh m''I'),
23+
('1f8ed2f3-56f3-459b-8f3e-6d8d654a1f6c','a palindrome','racecar','racecar'),
24+
('b9e7dec1-c6df-40bd-9fa3-cd7ded010c4c','an even-sized word','drawer','reward');
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"",""
2+
"robot",""
3+
"Ramen",""
4+
"I'm hungry!",""
5+
"racecar",""
6+
"drawer",""
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Schema: CREATE TABLE "reverse-string" (input TEXT NOT NULL, result TEXT);
2+
-- Task: update the reverse-string table and set the result based on the input.

0 commit comments

Comments
 (0)