Data update

This commit is contained in:
Ingy döt Net 2025-08-11 18:05:26 -07:00
parent 4d5544505c
commit 4924dd0264
3073 changed files with 55820 additions and 4408 deletions

View file

@ -0,0 +1,32 @@
create or replace function ranges(x, y, z, one, three, seven) as (
range(-three, ((1 + 3) ^ 3)::BIGINT, three) ||
range( -seven, 1 + seven, x) ||
range( 555, 1 + 550 - y) ||
range( 22,-1 -28, -three) ||
range(1927 , 1 + 1939 ) ||
range(x , y, z) ||
range((11 ^ x)::BIGINT, 1 + ( 11 ^ x)::BIGINT + one)
);
create or replace function task(x,y,z, one, three, seven) as table (
with recursive lst as (select ranges(x,y,z, one, three, seven) as lst),
cte as (
select 1 as ix, -- index into ranges()
0 as j,
0 as sum,
1 as prod -- start with a product of unity
union all
select ix + 1 as ix,
lst.lst[ix] as j,
(sum + (@j)) as sum,
if ((@prod) < (2 ^ 27)::BIGINT and j != 0,
prod * j,
prod) as prod
from cte, lst
where ix <= 1 + length(lst)
)
select last(sum) as sum, last(prod) as prod
from cte
);
from task(5, -5, -2, 1, 3, 7);

View file

@ -0,0 +1,30 @@
procedure main()
prod := 1
sum := 0
x := +5
y := -5
z := -2
one := 1
three := 3
seven := 7
every j := resultsof {
-three to 3^3 by three ,
-seven to +seven by x ,
555 to 550 - y ,
22 to -28 by -three ,
1927 to 1939 ,
x to y by z ,
11^x to 11^x + one
} do {
sum := sum + abs(j)
if abs(prod) < 2^27 & j ~= 0 then prod := prod*j
}
write(" sum = ", sum)
write("prod = ", prod)
end
procedure resultsof(celist)
every ce := !celist do
while e := @ce do suspend e
end

View file

@ -0,0 +1,27 @@
procedure main()
prod := 1
sum := 0
x := +5
y := -5
z := -2
one := 1
three := 3
seven := 7
i_to_h_by_k := proc("...",3) # i_to_h_by_k(i,h,k)
# same as "i to h by k"
every j := i_to_h_by_k ! ![
[ -three , 3^3 , three ] ,
[ -seven , +seven , x ] ,
[ 555 , 550 - y , one ] , # list of argument lists
[ 22 , -28 , -three ] , # (i,h,k)
[ 1927 , 1939 , one ] ,
[ x , y , z ] ,
[ 11^x , 11^x + one , one ]
] do {
sum := sum + abs(j)
if abs(prod) < 2^27 & j ~= 0 then prod := prod*j
}
write(" sum = ", sum)
write("prod = ", prod)
end

View file

@ -0,0 +1,60 @@
local prod = 1
local sum = 0
local x = 5
local y = -5
local z = -2
local one = 1
local three = 3
local seven = 7
local p = math.round(11 ^ x)
local j = 0
local function process()
sum += math.abs(j)
if math.abs(prod) < (1 << 27) and j != 0 then prod *= j end
end
j = -three
while j <= 3 ^ 3 do
process()
j += three
end
j = -seven
while j <= seven do
process()
j += x
end
j = 555
while j <= 550 - y do
process()
++j
end
j = 22
while j >= -28 do
process()
j -= three
end
j = 1927
while j <= 1939 do
process()
++j
end
j = x
while j >= y do
process()
j -= -z
end
j = p
while j <= p + one do
process()
++j
end
print($"sum = {string.formatint(sum)}")
print($"prod = {string.formatint(prod)}")

View file

@ -0,0 +1,59 @@
Rebol [
title: "Rosetta code: Loops/With multiple ranges"
file: %Loops-With_multiple_ranges.r3
url: https://rosettacode.org/wiki/Loops/With_multiple_ranges
needs: 3.0.0
note: {Based on Rosetta Code Red language task solution}
]
;; Define a function that iterates over multiple ranges
for-ranges: function/with ['word ranges body][
;; Clear temporary buffer
inp: clear []
;; Bind ranges dialect to context of this function
bind ranges self
foreach c reduce ranges [append inp c]
foreach i inp [set word i do body]
] context [
inp: copy []
;; Define a custom operator 'to' that creates a range from start to end
;- Note: `to` function redefinition!
to: make op! function [start end][
res: copy []
repeat n 1 + absolute to-integer end - start [
append res start + either start > end [1 - n][n - 1]
]
]
;; Define a custom operator 'by' that extracts every nth element from a series
by: make op! function [s w] [extract s absolute w]
]
;; Initialize variables
prod: 1
sum: 0
x: +5
y: -5
z: -2
one: 1
three: 3
seven: 7
;; Execute for-ranges with variable 'j' over multiple range expressions
for-ranges j [
0 - three to (3 ** 3) by three
0 - seven to seven by x
555 to (550 - y)
22 to -28 by (0 - three)
1927 to 1939
x to y by z
11 ** x to (11 ** x + one)
][
;; Body of the loop executed for each value of j
;; Add absolute value of j to sum
sum: to-integer sum + absolute j
;; Multiply prod by j if conditions are met:
;; - absolute value of prod is less than 2^27 (134,217,728)
;; - j is not zero (to avoid making prod zero)
if all [(absolute prod) < power 2 27 j <> 0] [prod: prod * j]
]
;; Print the final results
print ["sum: " sum "^/prod:" prod]