Data update
This commit is contained in:
parent
4d5544505c
commit
4924dd0264
3073 changed files with 55820 additions and 4408 deletions
50
Task/Loops-Nested/DuckDB/loops-nested.duckdb
Normal file
50
Task/Loops-Nested/DuckDB/loops-nested.duckdb
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
# PRN in range(0,n)
|
||||
create or replace function prn(n) as
|
||||
trunc(random() * n)::BIGINT;
|
||||
|
||||
create or replace function random_array(n, twenty) as
|
||||
list_transform(range(0,n), x-> 1+prn(twenty));
|
||||
|
||||
create or replace function random_matrix(m, n, twenty) as (
|
||||
list_transform(range(0,m), x -> random_array(n, twenty))
|
||||
);
|
||||
|
||||
# Scanning the matrix row-wise, return a list of the cells up to
|
||||
# but excluding n, or else [].
|
||||
# WARNING: The matrix `matrix` should be materialized before entry!
|
||||
# Note the type declaration for `matrix`.
|
||||
create or replace function matrix_up_to(matrix, n) as (
|
||||
if (length(matrix) = 0, [],
|
||||
(with recursive matrix_t as (select matrix::BIGINT[][] as m),
|
||||
cte1 as (
|
||||
select 1 as ix,
|
||||
coalesce(list_position(m[1], n), 0) as p,
|
||||
[] as s
|
||||
from matrix_t
|
||||
union all
|
||||
select ix+1 as ix,
|
||||
if (p = 0, coalesce(list_position(m[ix+1], n), 0),
|
||||
-1) as p,
|
||||
(s || if (@p = 1, [],
|
||||
if (p>0, m[ix][:p-1],
|
||||
m[ix] ) )) as s
|
||||
from cte1, matrix_t
|
||||
where p != -1 and
|
||||
ix <= length(m)
|
||||
)
|
||||
-- for verification: select ((last(s), any_value(matrix)))
|
||||
select last(s)
|
||||
from cte1
|
||||
) )
|
||||
);
|
||||
|
||||
.mode list
|
||||
.header off
|
||||
|
||||
# Because of the way DuckDB inlines functions, the matrix produced
|
||||
# by random_matrix() must be materialized before it can be properly handled.
|
||||
# Using DuckDB V1.1, this can be done using SET VARIABLE:
|
||||
|
||||
set variable matrix = random_matrix(10,5, 20);
|
||||
|
||||
select matrix_up_to( getvariable('matrix'), 20 ) as head;
|
||||
18
Task/Loops-Nested/Pluto/loops-nested.pluto
Normal file
18
Task/Loops-Nested/Pluto/loops-nested.pluto
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
local a = {}
|
||||
for i = 1, 20 do
|
||||
a[i] = {}
|
||||
for j = 1, 20 do
|
||||
a[i][j] = math.random(1, 20)
|
||||
end
|
||||
end
|
||||
|
||||
for i = 1, 20 do
|
||||
for j = 1, 20 do
|
||||
io.write(string.format("%2d ", a[i][j]))
|
||||
if a[i][j] == 20 then
|
||||
print()
|
||||
break 2 -- break from outer loop
|
||||
end
|
||||
if j % 10 == 0 then print() end
|
||||
end
|
||||
end
|
||||
|
|
@ -12,7 +12,7 @@ random/seed now
|
|||
|
||||
; Create array and fill with random numbers, range 1..20.
|
||||
soup: array [10 10]
|
||||
repeat row soup [forall row [row/1: random 20]]
|
||||
foreach row soup [forall row [row/1: random 20]]
|
||||
|
||||
print "Loop break using state variable:"
|
||||
done: no
|
||||
|
|
|
|||
38
Task/Loops-Nested/Zig/loops-nested.zig
Normal file
38
Task/Loops-Nested/Zig/loops-nested.zig
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
const std = @import("std");
|
||||
|
||||
const ARR_ROWS = 10;
|
||||
const ARR_COLS = 10;
|
||||
|
||||
pub fn main() !void {
|
||||
const stdout = std.io.getStdOut().writer();
|
||||
var prng = std.Random.DefaultPrng.init(blk: {
|
||||
var seed: u64 = undefined;
|
||||
try std.posix.getrandom(std.mem.asBytes(&seed));
|
||||
break :blk seed;
|
||||
});
|
||||
const rand = prng.random();
|
||||
var bi_arr: [ARR_ROWS][ARR_COLS]u8 = undefined;
|
||||
|
||||
// generate values for the bi-dimensional array
|
||||
for (0..ARR_ROWS) |row| {
|
||||
for (0..ARR_COLS) |col| {
|
||||
bi_arr[row][col] = rand.intRangeAtMost(u8, 0, 20);
|
||||
}
|
||||
}
|
||||
|
||||
// search for the value 20 in the bi-dimensional array
|
||||
const target: u8 = 20;
|
||||
search: for (0..ARR_ROWS) |row| {
|
||||
for (0..ARR_COLS) |col| {
|
||||
try stdout.print("{d:2} ", .{bi_arr[row][col]});
|
||||
|
||||
if (bi_arr[row][col] == target) {
|
||||
break :search;
|
||||
}
|
||||
}
|
||||
|
||||
try stdout.print("\n", .{});
|
||||
}
|
||||
|
||||
try stdout.print("\n", .{});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue