Classic Arrays in Ring Language

60 views
Skip to first unread message

Bert Mariani

unread,
Sep 11, 2025, 10:42:33 AMSep 11
to The Ring Programming Language

Hello Mahmoud et ALL

Classic Arrays in Ring Language
Ring Language - Classic Arrays Implementation
Demonstrating traditional array operations for numerical calculations

Attached:  Array-Ring-Classic.ring

At the start it will run a Demo inside the App 
Using the built in Functions and Class
That shows Results of  assorted Array Calculations 

See below for:
    - Functions
    - Class
    - Output

===========================
FUNCTIONS
func arrayAdd(arr1, arr2)
func arraySubtract(arr1, arr2)
func arrayScalarMultiply(arr, scalar)
func arrayMultiply(arr1, arr2)
func arrayDotProduct(arr1, arr2)
func arraySum(arr)
func arrayMean(arr)
func arrayMin(arr)
func arrayMax(arr)
func matrixMultiply(mat1, mat2)
func arrayStandardDeviation(arr)
func arrayLinearRegression(x_arr, y_arr)

CLASS
Class ClassicArray
func init(array_size, initial_value)
func getElement(index)
func setElement(index, value)
func calculateFlatIndex(indices)
func getSize()
func getDimensions()
func fill(value)
func print()

============================
OUTPUT Result of Demo

Classic Arrays in Ring Language
================================

1D Array Operations:
--------------------
Array 1: [2, 4, 6, 8, 10]
Array 2: [11, 12, 13, 14, 15]
Addition: [13, 16, 19, 22, 25]
Subtraction: [-9, -8, -7, -6, -5]
Scalar multiply by 3: [6, 12, 18, 24, 30]
Dot product: 410
Array 1 sum: 30
Array 1 mean: 6
Array 1 min: 2
Array 1 max: 10
Array 1 std dev: 2.83

2D Array (Matrix) Operations:
-----------------------------
Matrix 1:
[1, 2, 3]
[4, 5, 6]
[7, 8, 9]
Matrix 2:
[2, 3, 4]
[3, 4, 5]
[4, 5, 6]
Matrix multiplication result:
[20, 26, 32]
[47, 62, 77]
[74, 98, 122]
Statistical Analysis Example:
-----------------------------
X data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Y data: [9, 8, 9, 18, 13, 13, 15, 26, 28, 23]
Linear regression:
  Slope: 2.07
  Intercept: 4.80
  Equation: y = 2.07x + 4.80

Performance Comparison:
-----------------------
Created arrays of size 1000
Array addition time: 3 clock ticks
Dot product time: 2 clock ticks
Dot product result: 2554441

Classic array operations completed!

==========================


Array-Ring-Classic.ring

Mahmoud Fayed

unread,
Sep 11, 2025, 10:51:52 AMSep 11
to The Ring Programming Language
Hello Bert

Thanks for sharing :D


Greetings,
Mahmoud

CalmoSoft

unread,
Sep 12, 2025, 2:02:16 AMSep 12
to The Ring Programming Language
Hello Bert,

You can add  matrix transposition on Rosetta Code

Greetings,
Gal Zsolt
CalmoSoft

Bert Mariani

unread,
Sep 12, 2025, 11:37:57 AMSep 12
to The Ring Programming Language
Hello Calmo

Matrix Transposition for Ring -- Already exists in Rosetta Code
Ring Documentation Section 43.35  also has an example

===========================
RING
load "stdlib.ring"
transpose = newlist(5,4)
matrix = [[78,19,30,12,36], [49,10,65,42,50], [30,93,24,78,10], [39,68,27,64,29]]
for i = 1 to 5
    for j = 1 to 4
        transpose[i][j] = matrix[j][i]
        see "" + transpose[i][j] + " "
    next
    see nl
next

OUTPUT
78 49 30 39
19 10 93 68
30 65 24 27
12 42 78 64
36 50 10 29

=================================
Ring Documentation
43.35 MatrixTrans() Function

Transpose an arbitrarily sized rectangular Matrix
Load "stdlibcore.ring"
# Transpose an arbitrarily sized rectangular Matrix.
Puts("Test Matrixtrans()")
matrix = [[78,19,30,12,36], [49,10,65,42,50], [30,93,24,78,10], [39,68,27,64,29]]
see Matrixtrans(matrix)

CalmoSoft

unread,
Sep 15, 2025, 3:03:06 AMSep 15
to The Ring Programming Language
Hello Bert,

Thanks for your informations.

Greetings,
Gal Zsolt
CalmoSoft

Reply all
Reply to author
Forward
0 new messages