Data update
This commit is contained in:
parent
4d5544505c
commit
4924dd0264
3073 changed files with 55820 additions and 4408 deletions
8
Task/Bitwise-IO/DuckDB/bitwise-io-1.duckdb
Normal file
8
Task/Bitwise-IO/DuckDB/bitwise-io-1.duckdb
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# s should be a bitstring.
|
||||
# Right-pad s with 0s so that the length of the output string is a multiple of 8.
|
||||
CREATE OR REPLACE FUNCTION print_bits(s) as (
|
||||
format('{:0<{}}', s, (ceil(length(s) / 8) * 8)::INT)
|
||||
);
|
||||
|
||||
# Example:
|
||||
select print_bits('101'::BITSTRING);
|
||||
13
Task/Bitwise-IO/DuckDB/bitwise-io-2.duckdb
Normal file
13
Task/Bitwise-IO/DuckDB/bitwise-io-2.duckdb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# "Compress" a string by printing it as a bitstring without the left-most bit of each byte
|
||||
CREATE OR REPLACE FUNCTION sevenbits(str) as (
|
||||
select string_agg(format('{}', ascii(s)::BITSTRING)[-7:], '')
|
||||
from (select unnest(regexp_extract_all(str, '.')) as s)
|
||||
);
|
||||
|
||||
# Undo sevenbits()
|
||||
CREATE OR REPLACE FUNCTION from_sevenbits(str) as (
|
||||
select string_agg(chr(s::BIT::INT), '')
|
||||
from (select unnest(regexp_extract_all(str, '.......')) as s)
|
||||
);
|
||||
|
||||
select from_sevenbits(sevenbits('abracadabra'));
|
||||
Loading…
Add table
Add a link
Reference in a new issue