Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
|
|
@ -0,0 +1,64 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with Ada.Containers.Vectors;
|
||||
|
||||
procedure Main is
|
||||
package int_vector is new Ada.Containers.Vectors
|
||||
(Index_Type => Natural, Element_Type => Integer);
|
||||
use int_vector;
|
||||
|
||||
summing_values : Vector := Empty_Vector;
|
||||
|
||||
prod : Integer := 1;
|
||||
sum : Integer := 0;
|
||||
x : Integer := 5;
|
||||
y : Integer := -5;
|
||||
z : Integer := -2;
|
||||
N : Integer;
|
||||
begin
|
||||
N := -3;
|
||||
while N <= 3**3 loop
|
||||
summing_values.Append (N);
|
||||
N := N + 3;
|
||||
end loop;
|
||||
|
||||
N := -7;
|
||||
while N <= 7 loop
|
||||
summing_values.Append (N);
|
||||
N := N + x;
|
||||
end loop;
|
||||
|
||||
for I in 555 .. 550 - y loop
|
||||
summing_values.Append (I);
|
||||
end loop;
|
||||
|
||||
N := 22;
|
||||
while N >= -28 loop
|
||||
summing_values.Append (N);
|
||||
N := N - 3;
|
||||
end loop;
|
||||
|
||||
for I in 1_927 .. 1_939 loop
|
||||
summing_values.Append (I);
|
||||
end loop;
|
||||
|
||||
N := x;
|
||||
while N >= y loop
|
||||
summing_values.Append (N);
|
||||
N := N + z;
|
||||
end loop;
|
||||
|
||||
for I in 11**x .. 11**x + 1 loop
|
||||
summing_values.Append (I);
|
||||
end loop;
|
||||
|
||||
for value of summing_values loop
|
||||
sum := sum + abs (value);
|
||||
if abs (prod) < 2**27 and then value /= 0 then
|
||||
prod := prod * value;
|
||||
end if;
|
||||
end loop;
|
||||
|
||||
Put_Line ("sum = " & sum'Image);
|
||||
Put_Line ("prod = " & prod'Image);
|
||||
|
||||
end Main;
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
prod = 1
|
||||
sum = 0
|
||||
x = +5
|
||||
y = -5
|
||||
z = -2
|
||||
one = 1
|
||||
three = 3
|
||||
seven = 7
|
||||
|
||||
Iterator(Int32).chain([(-three).step(to: 3**3, by: three),
|
||||
(-seven).step(to: +seven, by: x),
|
||||
555.step(to: 550 - y),
|
||||
22.step(to: -28, by: -three),
|
||||
1927.step(to: 1939),
|
||||
x.step(to: y, by: z),
|
||||
(11**x).step(to: 11**x + one)]).each do |j|
|
||||
sum += j.abs
|
||||
if prod.abs < 2**27 && j != 0
|
||||
prod *= j
|
||||
end
|
||||
end
|
||||
|
||||
p! sum, prod
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
let prod = 1, sum = 0;
|
||||
const x = 5, y = -5, z = -2;
|
||||
const one = 1, three = 3, seven = 7;
|
||||
|
||||
function process(j) {
|
||||
sum += Math.abs(j);
|
||||
if (Math.abs(prod) < 2 ** 27 && j !== 0) {
|
||||
prod *= j;
|
||||
}
|
||||
}
|
||||
|
||||
function multifor(f, arr) {
|
||||
function wraploop(start, stop, step = 1) {
|
||||
for (let j = start; Math.abs(j) <= Math.abs(stop); j += step) {
|
||||
f(j);
|
||||
}
|
||||
}
|
||||
for (const subarr of arr) {
|
||||
wraploop(...subarr);
|
||||
}
|
||||
}
|
||||
|
||||
const test_ranges = [[-three, 3 ** 3, three],
|
||||
[-seven, seven, x],
|
||||
[555, 550 - y],
|
||||
[22, -28, -three],
|
||||
[1927, 1939],
|
||||
[x, y, z],
|
||||
[11 ** x, 11 ** x + one]];
|
||||
|
||||
multifor(process, test_ranges);
|
||||
console.log(`Sum: ${sum}`);
|
||||
console.log(`Product: ${prod}`);
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
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)$
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
p <- 1
|
||||
s <- 0
|
||||
x <- 5
|
||||
y <- -5
|
||||
z <- -2
|
||||
one <- 1
|
||||
three <- 3
|
||||
seven <- 7
|
||||
|
||||
process <- function(j) {
|
||||
s <<- s + abs(j)
|
||||
if(abs(p) < 2^27 && j!=0) p <<- p*j
|
||||
}
|
||||
|
||||
multifor <- function(f, l){
|
||||
for(v in l){
|
||||
vseq <- do.call(seq, as.list(v))
|
||||
for(j in vseq) f(j)
|
||||
}
|
||||
}
|
||||
|
||||
test_ranges <- list(c(-three, 3^3, three),
|
||||
c(-seven, seven, x),
|
||||
c(555, 550-y),
|
||||
c(22, -28, -three),
|
||||
c(1927, 1939),
|
||||
c(x, y, z),
|
||||
c(11^x, 11^x + one))
|
||||
|
||||
multifor(process, test_ranges)
|
||||
cat("Sum:", s, "\nProduct:", p)
|
||||
|
|
@ -0,0 +1,207 @@
|
|||
# riscv assembly raspberry pico2 rp2350
|
||||
# program loopmulti.s
|
||||
# connexion putty com3
|
||||
/*********************************************/
|
||||
/* CONSTANTES */
|
||||
/********************************************/
|
||||
/* for this file see risc-v task include a file */
|
||||
.include "../../../constantesRiscv.inc"
|
||||
/****************************************************/
|
||||
/* MACROS */
|
||||
/****************************************************/
|
||||
#.include "../ficmacrosriscv.inc" # only for debugging
|
||||
/*******************************************/
|
||||
/* INITIALED DATAS */
|
||||
/*******************************************/
|
||||
.data
|
||||
szMessStart: .asciz "Program riscv start.\r\n"
|
||||
szMessEndOk: .asciz "Program riscv end OK.\r\n"
|
||||
szCariageReturn: .asciz "\r\n"
|
||||
szMessResult: .asciz "Result = " # message result
|
||||
|
||||
|
||||
.align 2
|
||||
/*******************************************/
|
||||
/* UNINITIALED DATA */
|
||||
/*******************************************/
|
||||
.bss
|
||||
sConvArea: .skip 24
|
||||
|
||||
.align 2
|
||||
iSum: .skip 4
|
||||
iProd: .skip 4
|
||||
|
||||
|
||||
/**********************************************/
|
||||
/* SECTION CODE */
|
||||
/**********************************************/
|
||||
.text
|
||||
.global main
|
||||
|
||||
main:
|
||||
call stdio_init_all # général init
|
||||
1: # start loop connexion
|
||||
li a0,0 # raz argument register
|
||||
call tud_cdc_n_connected # waiting for USB connection
|
||||
beqz a0,1b # return code = zero ? yes -> loop
|
||||
|
||||
la a0,szMessStart # message address
|
||||
call writeString # display message
|
||||
|
||||
la s0,iProd
|
||||
li t0,1
|
||||
sw t0,(s0) # init produit
|
||||
la s1,iSum
|
||||
li t0,0
|
||||
sw t0,(s1) # init sum
|
||||
|
||||
li s2,5 # x
|
||||
li s3,-5 # y
|
||||
li s4,-2 # z
|
||||
li s5,1 # un
|
||||
li s6,3 # trois
|
||||
li s7,7 # sept
|
||||
li a0,3
|
||||
li a1,3
|
||||
call computePow # compute 3 pow 3
|
||||
mv s8,a0 # save result
|
||||
neg s9,s6 # s9 = - three
|
||||
1:
|
||||
mv a0,s9
|
||||
call computeSumProd
|
||||
add s9,s9,s6
|
||||
ble s9,s8,1b
|
||||
|
||||
neg s9,s7
|
||||
2:
|
||||
mv a0,s9
|
||||
call computeSumProd
|
||||
add s9,s9,s2 # add five
|
||||
ble s9,s7,2b
|
||||
|
||||
li s9,550
|
||||
sub s8,s9,s3 # - y
|
||||
li s9,555
|
||||
3:
|
||||
mv a0,s9
|
||||
call computeSumProd
|
||||
addi s9,s9,1
|
||||
ble s9,s8,3b
|
||||
|
||||
li s9,22
|
||||
li s8,-28
|
||||
4:
|
||||
mv a0,s9
|
||||
call computeSumProd
|
||||
sub s9,s9,s6 # decrement by 3
|
||||
bge s9,s8,4b
|
||||
|
||||
li s9,1927
|
||||
li s8,1939
|
||||
5:
|
||||
mv a0,s9
|
||||
call computeSumProd
|
||||
addi s9,s9,1 # increment by 1
|
||||
ble s9,s8,5b
|
||||
|
||||
mv s9,s2 # x
|
||||
neg s8,s4 # - 2
|
||||
6:
|
||||
mv a0,s9
|
||||
call computeSumProd
|
||||
sub s9,s9,s8 #
|
||||
bge s9,s3,6b
|
||||
|
||||
mv a0,s2
|
||||
li a1,11
|
||||
call computePow # compute 3 pow 3
|
||||
|
||||
add s8,a0,s5 # add 1
|
||||
mv s9,a0
|
||||
7:
|
||||
mv a0,s9
|
||||
call computeSumProd
|
||||
addi s9,s9,1 # increment by 1
|
||||
ble s9,s8,7b
|
||||
|
||||
lw a0,(s1)
|
||||
la a1,sConvArea # conversion area
|
||||
call conversion10S # conversion décimale
|
||||
|
||||
la a0,szMessResult
|
||||
call writeString # display message
|
||||
la a0,sConvArea
|
||||
call writeString
|
||||
la a0,szCariageReturn
|
||||
call writeString
|
||||
|
||||
lw a0,(s0)
|
||||
la a1,sConvArea # conversion area
|
||||
call conversion10S # conversion décimale
|
||||
|
||||
la a0,szMessResult
|
||||
call writeString # display message
|
||||
la a0,sConvArea
|
||||
call writeString
|
||||
la a0,szCariageReturn
|
||||
call writeString
|
||||
|
||||
|
||||
la a0,szMessEndOk # message address
|
||||
call writeString # display message
|
||||
call getchar
|
||||
100: # final loop
|
||||
j 100b
|
||||
/**************************************************/
|
||||
/* compute pow */
|
||||
/**************************************************/
|
||||
/* a0 value */
|
||||
/* a1 pow */
|
||||
computePow: # INFO: computePow
|
||||
addi sp, sp, -4
|
||||
sw ra, 0(sp)
|
||||
mv t0,a0
|
||||
li a0,1
|
||||
1:
|
||||
blez t0,100f
|
||||
mul a0,a1,a0
|
||||
addi t0,t0,-1
|
||||
j 1b
|
||||
100:
|
||||
lw ra, 0(sp)
|
||||
addi sp, sp, 4
|
||||
ret
|
||||
/**************************************************/
|
||||
/* compute the sum and prod */
|
||||
/**************************************************/
|
||||
/* a0 value */
|
||||
computeSumProd: # INFO: computeSumProd
|
||||
addi sp, sp, -4
|
||||
sw ra, 0(sp)
|
||||
srai t0,a0,31
|
||||
xor t2,a0,t0
|
||||
sub t2,t2,t0 # compute absolue value
|
||||
la t3,iSum # load sum
|
||||
lw t1,(t3)
|
||||
add t1,t1,t2
|
||||
sw t1,(t3)
|
||||
beqz a0,100f # if j=0
|
||||
la t3,iProd # load product
|
||||
lw t1,(t3)
|
||||
srai t2,t1,31 # compute absolute value of prod
|
||||
xor t4,t1,t2
|
||||
sub t2,t4,t2
|
||||
li t5,1<<27 # compare 2 puissance 27
|
||||
bgt t2,t5,100f
|
||||
mul t1,a0,t1
|
||||
sw t1,(t3) # store prod
|
||||
100:
|
||||
lw ra, 0(sp)
|
||||
addi sp, sp, 4
|
||||
ret
|
||||
|
||||
/************************************/
|
||||
/* file include Fonctions */
|
||||
/***********************************/
|
||||
/* for this file see risc-v task include a file */
|
||||
.include "../../../includeFunctions.s"
|
||||
|
|
@ -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]
|
||||
Loading…
Add table
Add a link
Reference in a new issue