Skip to content

Commit a61bdbb

Browse files
authored
isbn verifier: update difficulty and example solution (#111)
1 parent 2fe425a commit a61bdbb

File tree

3 files changed

+24
-29
lines changed

3 files changed

+24
-29
lines changed

config.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@
8282
"prerequisites": [],
8383
"difficulty": 2
8484
},
85+
{
86+
"slug": "isbn-verifier",
87+
"name": "ISBN Verifier",
88+
"uuid": "a0a1cb68-b587-4d30-bf1c-819814847637",
89+
"practices": [],
90+
"prerequisites": [],
91+
"difficulty": 2
92+
},
8593
{
8694
"slug": "leap",
8795
"name": "Leap",
@@ -250,14 +258,6 @@
250258
"prerequisites": [],
251259
"difficulty": 8
252260
},
253-
{
254-
"slug": "isbn-verifier",
255-
"name": "ISBN Verifier",
256-
"uuid": "a0a1cb68-b587-4d30-bf1c-819814847637",
257-
"practices": [],
258-
"prerequisites": [],
259-
"difficulty": 8
260-
},
261261
{
262262
"slug": "isogram",
263263
"name": "Isogram",

exercises/practice/isbn-verifier/.meta/example.sql

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,20 @@ UPDATE "isbn-verifier"
88

99
UPDATE "isbn-verifier"
1010
SET result = (
11-
WITH RECURSIVE verifier(isbn, digit, pos) AS (
12-
VALUES((
13-
WITH RECURSIVE cleaner(string, char) AS (
14-
VALUES(isbn, '')
15-
UNION ALL
16-
SELECT SUBSTRING(string, 2), SUBSTRING(string, 1, 1)
17-
FROM cleaner
18-
WHERE string <> ''
19-
)
20-
SELECT GROUP_CONCAT(char, '')
21-
FROM cleaner WHERE GLOB('[0-9X]', char)
22-
), '', 11)
23-
UNION ALL
24-
SELECT
25-
SUBSTRING(isbn, 2),
26-
IIF(SUBSTRING(isbn, 1, 1) = 'X', 10, SUBSTRING(isbn, 1, 1)),
27-
pos - 1
28-
FROM verifier
29-
WHERE isbn <> ''
30-
) SELECT SUM(digit * pos) % 11 = 0 FROM verifier WHERE digit <> ''
31-
)
11+
SUBSTRING(REPLACE(isbn,'-', ''), -10, 1) * 10 +
12+
SUBSTRING(REPLACE(isbn,'-', ''), -9, 1) * 9 +
13+
SUBSTRING(REPLACE(isbn,'-', ''), -8, 1) * 8 +
14+
SUBSTRING(REPLACE(isbn,'-', ''), -7, 1) * 7 +
15+
SUBSTRING(REPLACE(isbn,'-', ''), -6, 1) * 6 +
16+
SUBSTRING(REPLACE(isbn,'-', ''), -5, 1) * 5 +
17+
SUBSTRING(REPLACE(isbn,'-', ''), -4, 1) * 4 +
18+
SUBSTRING(REPLACE(isbn,'-', ''), -3, 1) * 3 +
19+
SUBSTRING(REPLACE(isbn,'-', ''), -2, 1) * 2 +
20+
IIF(
21+
SUBSTRING(REPLACE(isbn,'-', ''), -1, 1) = 'X',
22+
10,
23+
SUBSTRING(REPLACE(isbn,'-', ''), -1, 1)
24+
)
25+
) % 11 = 0
3226
WHERE result ISNULL
3327
;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
-- Schema: CREATE TABLE "isbn-verifier" (isbn TEXT NOT NULL, result BOOL);
22
-- Task: update the isbn-verifier table and set the result based on the isbn.
3+

0 commit comments

Comments
 (0)