Data update
This commit is contained in:
parent
72eb4943cb
commit
4d5544505c
2347 changed files with 62432 additions and 16731 deletions
15
Task/Arrays/Ballerina/arrays.ballerina
Normal file
15
Task/Arrays/Ballerina/arrays.ballerina
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import ballerina/io;
|
||||
|
||||
public function main() {
|
||||
// fixed length array
|
||||
int[4] a = [1, 4, 9, 16];
|
||||
// retrieve and print element at index 1 (zero indexing)
|
||||
io:println(a[1]);
|
||||
|
||||
// dynamic array
|
||||
int[] b = [];
|
||||
// push an element into it
|
||||
b.push(42);
|
||||
// retrieve and print last element added
|
||||
io:println(b[b.length() - 1]);
|
||||
}
|
||||
|
|
@ -1,8 +1,4 @@
|
|||
len f[] 4
|
||||
for i = 1 to len f[]
|
||||
f[i] = i
|
||||
.
|
||||
f[] &= 5
|
||||
for i = 1 to len f[]
|
||||
print f[i]
|
||||
.
|
||||
for i = 1 to len f[] : f[i] = i
|
||||
f[] &= 55
|
||||
print f[]
|
||||
|
|
|
|||
15
Task/Arrays/Excel/arrays-1.excel
Normal file
15
Task/Arrays/Excel/arrays-1.excel
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
=LET(
|
||||
ARRAY, LAMBDA(dim, [init], LET(
|
||||
Y, LAMBDA(SELF, arr,
|
||||
LAMBDA([a], [b],
|
||||
IF(ISOMITTED(b),
|
||||
INDEX(arr, a),
|
||||
SELF(SELF, IF(SEQUENCE(ROWS(arr)) = a, b, arr))
|
||||
)
|
||||
)
|
||||
),
|
||||
Y(Y, IF(SEQUENCE(dim), IF(ISOMITTED(init), "", init)))
|
||||
)),
|
||||
my_arr, ARRAY(5, 0),
|
||||
...
|
||||
)
|
||||
1
Task/Arrays/Excel/arrays-2.excel
Normal file
1
Task/Arrays/Excel/arrays-2.excel
Normal file
|
|
@ -0,0 +1 @@
|
|||
new_arr, my_arr(1, "val1")(4, "val4")
|
||||
16
Task/Arrays/Excel/arrays-3.excel
Normal file
16
Task/Arrays/Excel/arrays-3.excel
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
=LET(
|
||||
ARRAY, LAMBDA(dim, [init], LET(
|
||||
Y, LAMBDA(SELF, arr,
|
||||
LAMBDA([a], [b],
|
||||
IF(ISOMITTED(b),
|
||||
INDEX(arr, a),
|
||||
SELF(SELF, IF(SEQUENCE(ROWS(arr)) = a, b, arr))
|
||||
)
|
||||
)
|
||||
),
|
||||
Y(Y, IF(SEQUENCE(dim), IF(ISOMITTED(init), "", init)))
|
||||
)),
|
||||
my_arr, ARRAY(5, 0),
|
||||
new_arr, my_arr(1, "val1")(4, "val4"),
|
||||
new_arr()
|
||||
)
|
||||
9
Task/Arrays/OPL/arrays.opl
Normal file
9
Task/Arrays/OPL/arrays.opl
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
PROC main:
|
||||
REM Declare an integer array of 10 elements and a string array of 10 elements, each up to 12 characters long.
|
||||
LOCAL array1%(10),array2$(10,12)
|
||||
REM Array element count starts at 1.
|
||||
array1%(1)=128
|
||||
array2$(10)="Rosetta Code"
|
||||
PRINT array1%(1),array2$(10)
|
||||
GET
|
||||
ENDP
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
/*REXX program demonstrates a simple array usage. */
|
||||
a.='not found' /*value for all a.xxx (so far).*/
|
||||
do j=1 to 100 /*start at 1, define 100 elements*/
|
||||
a.j=-j*1000 /*define as negative J thousand. */
|
||||
end /*j*/ /*the above defines 100 elements.*/
|
||||
|
||||
say 'element 50 is:' a.50
|
||||
say 'element 3000 is:' a.3000
|
||||
/*stick a fork in it, we're done.*/
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
/*REXX program demonstrates array usage with mimicry. */
|
||||
a. = 'not found' /*value for all a.xxx (so far). */
|
||||
do j=1 to 100 /*start at 1, define 100 elements*/
|
||||
a.j = -j * 100 /*define element as -J hundred. */
|
||||
end /*j*/ /*the above defines 100 elements.*/
|
||||
|
||||
say 'element 50 is:' a(50)
|
||||
say 'element 3000 is:' a(3000)
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────A subroutine────────────────────────*/
|
||||
a: _a_ = arg(1); return a._a_
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
/*REXX program demonstrates array usage with mimicry. */
|
||||
a. = 00 /*value for all a.xxx (so far). */
|
||||
do j=1 to 100 /*start at 1, define 100 elements*/
|
||||
a.j = -j * 100 /*define element as -J hundred. */
|
||||
end /*j*/ /*the above defines 100 elements.*/
|
||||
|
||||
say 'element 50 is:' a(50)
|
||||
say 'element 3000 is:' a(3000)
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────A subroutine────────────────────────*/
|
||||
a: _a_ = arg(1); return a._a_
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
/*REXX program demonstrates array usage (with elements out-of-range).*/
|
||||
array. = 'out of range' /*define ALL elements to this. */
|
||||
|
||||
do j=-3000 to 3000 /*start at -3k, going up to +3k.*/
|
||||
array.j=j**2 /*define element as its square. */
|
||||
end /*j*/ /* [↑] defines 6,001 elements. */
|
||||
g=-7
|
||||
say g "squared is:" array.g
|
||||
say 7000 "squared is:" array.7000
|
||||
/*stick a fork in it, we're done.*/
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
/*REXX program demonstrates disjointed array usage. */
|
||||
yr. = 'year not supported' /*value for all yr.xxx (so far).*/
|
||||
|
||||
do k=600 to 1100 /*a bunch of years prior to 1800.*/
|
||||
yr.k=k "AD" /*Kth element as the year itself.*/
|
||||
end /*k*/ /* [↑] defines 501 elements.*/
|
||||
|
||||
do j=1800 to 2100 /*start at 1800, define a bunch. */
|
||||
yr.j=j 'AD' /*Jth element as the year itself.*/
|
||||
end /*j*/ /* [↑] defines 301 elements.*/
|
||||
|
||||
year=1946
|
||||
say 'DOB' year "is:" yr.year
|
||||
|
||||
year=1744
|
||||
say 'DOB' year "is:" yr.year
|
||||
/*stick a fork in it, we're done.*/
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
/*REXX program demonstrates array usage: sparse and disjointed. */
|
||||
yyy = -55 /*REXX must use this mechanism···*/
|
||||
a.yyy = 1e9 /*··· when assigning neg indices.*/
|
||||
|
||||
a.1 = 1000
|
||||
a.2 = 2000.0001
|
||||
a.7 = 7000
|
||||
a.2012 = 'out here in left field.'
|
||||
a.cat = 'civet, but not a true cat ─── belonging to the family Viverridae'
|
||||
a.civet = "A.K.A.: toddycats"
|
||||
/*┌────────────────────────────────────────────────────────────────────┐
|
||||
│ Array elements need not be continuous (nor even defined). They │
|
||||
│ can hold any manner of numbers, or strings (which can include any │
|
||||
│ characters, including null or '00'x characters). │
|
||||
│ │
|
||||
│ Array elements need not be numeric, as the above code demonstrates.│
|
||||
│ Indeed, the element "name" can be ANYTHING, even non-displayable │
|
||||
│ characters. To illustrate [↓]: │
|
||||
└────────────────────────────────────────────────────────────────────┘*/
|
||||
stuff=')g.u.t.s( or ½ of an intestine!'
|
||||
a.stuff=44
|
||||
/*┌────────────────────────────────────────────────────────────────────┐
|
||||
│ where the element name has special characters: blanks, and the │
|
||||
│ glyph of one-half (½), as well as the symbol used in REXX to │
|
||||
│ identify stemmed arrays (the period). │
|
||||
└────────────────────────────────────────────────────────────────────┘*/
|
||||
/*stick a fork in it, we're done.*/
|
||||
67
Task/Arrays/REXX/arrays.rexx
Normal file
67
Task/Arrays/REXX/arrays.rexx
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
-- 1 Jun 2025
|
||||
include Settings
|
||||
|
||||
say 'ARRAYS'
|
||||
say version
|
||||
say
|
||||
say 'A simple array...'
|
||||
do i = 1 to 100
|
||||
a.i=i*i
|
||||
end
|
||||
say 'Square of' 5 'is' a.5
|
||||
say 'Square of' 55 'is' a.55
|
||||
say
|
||||
say 'Mimic indexing...'
|
||||
say 'Square of' 5 'is' a(5)
|
||||
say 'Square of' 55 'is' a(55)
|
||||
say
|
||||
say 'A default value...'
|
||||
b. = 'Out of range'
|
||||
do i = 1 to 100
|
||||
b.i=1/i
|
||||
end
|
||||
say 'Inverse of' 5 'is' b.5
|
||||
say 'Inverse of' 55 'is' b.55
|
||||
say 'Inverse of' 555 'is' b.555
|
||||
say
|
||||
say 'An other index range...'
|
||||
do i = -100 to 100
|
||||
c.i=i*i*i
|
||||
end
|
||||
j=-55; say 'Cube of' j 'is' c.j
|
||||
j=-5; say 'Cube of' j 'is' c.j
|
||||
j=5; say 'Cube of' j 'is' c.j
|
||||
j=55; say 'Cube of' j 'is' c.j
|
||||
say
|
||||
say 'A sparse array...'
|
||||
d.='Not calculated'
|
||||
do i = 2 by 2 to 100
|
||||
d.i=-i
|
||||
end
|
||||
say 'Negative of' 55 'is' d.55
|
||||
say 'Negative of' 56 'is' d.56
|
||||
say
|
||||
say 'Special indices...'
|
||||
e.cat='civet'; say 'e.cat =' e.cat
|
||||
a1='dog'; e.a1='pitbull'
|
||||
a2=a1; say 'e.'a2 '=' e.a2
|
||||
a1='x.y.z'; e.a1='periods'
|
||||
a2=a1; say 'e.'a2 '=' e.a2
|
||||
a1='x y z'; e.a1='spaces'
|
||||
a2=a1; say 'e.'a2 '=' e.a2
|
||||
a1='└┴┬├─┼'; e.a1='specials'
|
||||
a2=a1; say 'e.'a2 '=' e.a2
|
||||
say
|
||||
say 'Element has no value...'
|
||||
signal off novalue
|
||||
say 'f.notassigned =' f.notassigned
|
||||
signal on novalue name Abend
|
||||
say 'f.notassigned =' f.notassigned
|
||||
exit
|
||||
|
||||
A:
|
||||
procedure expose a.
|
||||
arg xx
|
||||
return a.xx
|
||||
|
||||
include Abend
|
||||
|
|
@ -1,8 +1,11 @@
|
|||
set ary {}
|
||||
# empty list
|
||||
set arr {}
|
||||
|
||||
lappend ary 1
|
||||
lappend ary 3
|
||||
# 10 integers
|
||||
set arr [list 1 2 3 4 5 6 7 8 9 10 ]
|
||||
|
||||
lset ary 0 2
|
||||
|
||||
puts [lindex $ary 0]
|
||||
lappend arr 11
|
||||
lappend arr 12
|
||||
|
||||
puts stdout "$arr"
|
||||
|
|
|
|||
|
|
@ -1 +1,8 @@
|
|||
puts $ary; # Print the whole array
|
||||
set x [lindex $arr 4] ; # x <= 5
|
||||
|
||||
foreach n $arr {
|
||||
set idx [expr n -1]
|
||||
lset arr $idx [expr $n * $n]
|
||||
}
|
||||
|
||||
puts stdout "$arr"
|
||||
|
|
|
|||
2
Task/Arrays/Tcl/arrays-3.tcl
Normal file
2
Task/Arrays/Tcl/arrays-3.tcl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
set slice [lrange $arr 5 10]
|
||||
puts stdout "$slice"
|
||||
2
Task/Arrays/Tcl/arrays-4.tcl
Normal file
2
Task/Arrays/Tcl/arrays-4.tcl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
puts stdout "arr has [llength $arr] items."
|
||||
puts stdout "slice has [llength $slice] items."
|
||||
4
Task/Arrays/Tcl/arrays-5.tcl
Normal file
4
Task/Arrays/Tcl/arrays-5.tcl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
set r [lreverse $arr]
|
||||
set s [lsort -integer $r]
|
||||
puts stdout $r
|
||||
puts stdout $s
|
||||
10
Task/Arrays/Tcl/arrays-6.tcl
Normal file
10
Task/Arrays/Tcl/arrays-6.tcl
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
set term "calico"
|
||||
set fd [open "cats.txt" "r"]
|
||||
set contents [read $fd]
|
||||
set lines [split $contents "\n"]
|
||||
|
||||
foreach line $lines {
|
||||
if { [lsearch $line $term] > 0 } {
|
||||
puts "found $term in \"$line\""
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue