-
Notifications
You must be signed in to change notification settings - Fork 2
/
hello_world_2.rp
77 lines (72 loc) · 1.69 KB
/
hello_world_2.rp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* Hello World on Steroids */
def matrix int [2][2] printSquares(int x, matrix int [2][2] p) {
int s;
int i;
int j;
matrix int [3][5] m;
matrix int [3][5] test;
matrix int [3][5] after;
matrix int [2][1] vector1;
matrix int [1][2] vector2;
matrix int [2][2] vectorRes;
matrix int [2][2] vector3;
matrix int [2][2] vector4;
matrix int [2][2] vectorRes2;
vector1 = [[3],[4]];
vector3 = [[3,4],
[6,4]];
vector4 = [[3,2],
[1,1]];
s = x * x;
m = [[1,2,3,4,5],
[8,7,6,2,10],
[20,10,4,9,1]];
printStr("Square of x is: ");
print(s);
printStr("VALUE OF P");
print(p[0][0]);
printStr("All Values of matrix:");
for(j = 0; j < m.row; j = j + 1 ){
for(i = 0; i < m.col; i = i + 1){
test[j][i] = m[j][i] * 2;
print(m[j][i]);
}
}
printStr("Values of Matrix *2");
for(j = 0; j < m.row; j = j + 1 ){
for(i = 0; i < m.col; i = i + 1){
print(test[j][i]);
}
}
after = test-m;
after = after-m;
printStr("Values of test - m twice");
for(j = 0; j < m.row; j = j + 1 ){
for(i = 0; i < m.col; i = i + 1){
print(after[j][i]);
}
}
vector2 = vector1.T;
vectorRes = vector1*vector2;
printStr("Values of matrix multiplication");
for(j = 0; j < vectorRes.row; j = j + 1 ){
for(i = 0; i < vectorRes.col; i = i + 1){
print(vectorRes[j][i]);
}
}
vectorRes2 = vector3 ./ vector4;
printStr("Values of element wise matrix division");
for(j = 0; j < vectorRes2.row; j = j + 1 ){
for(i = 0; i < vectorRes2.col; i = i + 1){
print(vectorRes2[j][i]);
}
}
return vector3;
}
def void main() {
matrix int [2][2] m;
m = [[1,1],
[0,2]];
m = printSquares(3, m);
print(m[0][0]);
}