Data update
This commit is contained in:
parent
4d5544505c
commit
4924dd0264
3073 changed files with 55820 additions and 4408 deletions
23
Task/Run-length-encoding/DuckDB/run-length-encoding-1.duckdb
Normal file
23
Task/Run-length-encoding/DuckDB/run-length-encoding-1.duckdb
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
create or replace function run_length_encode(str) as table
|
||||
(WITH RECURSIVE cte AS (
|
||||
SELECT
|
||||
1 AS pos,
|
||||
1 AS counter,
|
||||
SUBSTRING(str, 1, 1) AS char,
|
||||
SUBSTRING(str, 2, 1) AS nextc,
|
||||
UNION ALL
|
||||
SELECT
|
||||
pos + 1 as pos,
|
||||
CASE
|
||||
WHEN nextc = char THEN counter + 1
|
||||
ELSE 1
|
||||
END as counter,
|
||||
nextc as char,
|
||||
SUBSTRING(str, 2 + pos, 1) as nextc
|
||||
FROM cte
|
||||
WHERE pos < LENGTH(str)
|
||||
)
|
||||
SELECT STRING_AGG( counter || char, '' ORDER BY pos) AS encoded_string
|
||||
FROM cte
|
||||
WHERE nextc != char
|
||||
);
|
||||
|
|
@ -0,0 +1 @@
|
|||
from run_length_encode('WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW');
|
||||
Loading…
Add table
Add a link
Reference in a new issue