RosettaCodeData/Task/Loops-With-multiple-ranges/Maxima/loops-with-multiple-ranges.maxima
2026-04-30 12:34:36 -04:00

23 lines
614 B
Text

block(p: 1, s: 0, x: 5, y: -5, z: -2, one: 1, three: 3, seven: 7)$
process(j) := block(
s: s + abs(j),
if abs(p) < 2^27 and j#0 then p: p*j
)$
multifor(f, l) := block(
wraploop(start, stop, by) := for j from start thru stop step by do(f(j)),
for subl in l do(apply(wraploop, subl))
)$
test_ranges: [[-three, 3^3, three],
[-seven, seven, x],
[555, 550-y, -one],
[22, -28, -three],
[1927, 1939, one],
[x, y, z],
[11^x, 11^x + one, one]]$
multifor(process, test_ranges)$
sprint("Sum:", s)$
sprint("Product:", p)$