Data update
This commit is contained in:
parent
4d5544505c
commit
4924dd0264
3073 changed files with 55820 additions and 4408 deletions
2
Task/Binary-digits/DuckDB/binary-digits-1.duckdb
Normal file
2
Task/Binary-digits/DuckDB/binary-digits-1.duckdb
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
SELECT n, format('{:b}', n)
|
||||
FROM (select unnest(range(0, 6) || [50, 9000]) as n);
|
||||
22
Task/Binary-digits/DuckDB/binary-digits-2.duckdb
Normal file
22
Task/Binary-digits/DuckDB/binary-digits-2.duckdb
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
# n is assumed to be a non-negative integer
|
||||
CREATE OR REPLACE FUNCTION binary_digits(n) as (
|
||||
WITH RECURSIVE cte(num, str) as (
|
||||
-- Base case
|
||||
SELECT n, ''
|
||||
UNION ALL
|
||||
-- Recursive case: divide by 2 and build the binary string
|
||||
SELECT num // 2, (num % 2) || str
|
||||
FROM cte
|
||||
WHERE num > 0
|
||||
)
|
||||
SELECT CASE WHEN str = '' THEN '0' ELSE str END
|
||||
FROM cte
|
||||
WHERE num = 0
|
||||
LIMIT 1
|
||||
);
|
||||
|
||||
select n, binary_digits(n)
|
||||
from (select unnest(range(0, 6) || [50, 9000]) as n);
|
||||
|
||||
.maxwidth 200
|
||||
select n, binary_digits(n) from (select 123456789123456789123456789123456789 as n)
|
||||
Loading…
Add table
Add a link
Reference in a new issue