-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f4f8a0
commit 84e6be6
Showing
4 changed files
with
145 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
x = 5 -- x is a number | ||
y = "hello" -- y is a string | ||
z = true -- z is a boolean | ||
|
||
|
||
if x > 5 then | ||
print("x is greater than 5") | ||
else | ||
print("x is not greater than 5") | ||
end | ||
|
||
for i = 1, 10 do | ||
print(i) | ||
end | ||
|
||
while x > 0 do | ||
x = x - 1 | ||
print(x) | ||
end | ||
|
||
|
||
function add(x, y) | ||
return x + y | ||
end | ||
|
||
result = add(3, 4) | ||
print(result) -- prints 7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import arrays | ||
import os | ||
import time | ||
import math | ||
import rand | ||
import rand.mt19937 | ||
|
||
struct PRNGOwn { | ||
mut: | ||
rng rand.PRNG | ||
} | ||
|
||
__global ( | ||
max_val = u64(1024*1024*1024*1024*1024*1024*8) | ||
max_val_half = max_val / u64(2) | ||
) | ||
fn new() PRNGOwn { | ||
return PRNGOwn { | ||
rng: &rand.PRNG(mt19937.MT19937RNG{}) | ||
} | ||
} | ||
|
||
fn (mut self PRNGOwn) next_f64() f64 { | ||
return (f64(self.rng.u64() % max_val) - max_val_half) / f64(max_val_half) * f64(2) | ||
} | ||
|
||
fn main() { | ||
mut rng_own := new() | ||
|
||
n := u64(1024) | ||
len_i := n | ||
len_j := n | ||
len_k := n | ||
|
||
len_1 := len_i * len_k | ||
len_2 := len_k * len_j | ||
len_3 := len_i * len_j | ||
|
||
mut v_1 := []f64{len: int(len_1)} | ||
mut v_2 := []f64{len: int(len_2)} | ||
mut v_3 := []f64{len: int(len_3)} | ||
|
||
for i := u64(0); i < len_1; i += 1 { | ||
v_1[i] = rng_own.next_f64() | ||
} | ||
|
||
for i := u64(0); i < len_2; i += 1 { | ||
v_2[i] = rng_own.next_f64() | ||
} | ||
|
||
sw := time.new_stopwatch() | ||
for y := u64(0); y < len_i; y += 1 { | ||
for z := u64(0); z < len_k; z += 1 { | ||
for x := u64(0); x < len_j; x += 1 { | ||
v_3[y * len_j + x] += v_1[y * len_k + z] * v_2[z * len_j + x] | ||
} | ||
} | ||
} | ||
elapsed := sw.elapsed().microseconds() | ||
|
||
println('elapsed: ${elapsed} us') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import os | ||
|
||
struct Point { | ||
x int | ||
y int | ||
} | ||
|
||
struct Line { | ||
p1 Point | ||
p2 Point | ||
} | ||
|
||
type ObjectSumType = Line | Point | ||
|
||
fn main() { | ||
println("hello world") | ||
|
||
println(os.args) | ||
|
||
a := i32(123) | ||
assert a == i32(123) | ||
|
||
println("a: ${a}") | ||
|
||
mut l_vals := []int{len: 7, init: it * 3 + 1} | ||
println("l_vals: ${l_vals}") | ||
|
||
mut object_list := []ObjectSumType{} | ||
object_list << Point{1, 1} | ||
object_list << Line{ | ||
p1: Point{3, 3} | ||
p2: Point{4, 4} | ||
} | ||
dump(object_list) | ||
|
||
mut l_vals_rep := l_vals.repeat(2) | ||
idx1 := int(1) | ||
idx2 := int(7) | ||
mut l_vals_rep_2 := l_vals_rep[idx1..idx2] | ||
println("l_vals_rep: ${l_vals_rep}") | ||
println("l_vals_rep_2: ${l_vals_rep_2}") | ||
} |