-
Notifications
You must be signed in to change notification settings - Fork 66
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
4b9c746
commit faff790
Showing
2 changed files
with
51 additions
and
0 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,21 @@ | ||
f = compiler.load([[ | ||
local arr: integer[] = table.intarray(10) | ||
arr[0] = 10 | ||
arr[4] = 2 | ||
arr[11] = 6 | ||
local sum: integer = 0 | ||
for i=0,11 do | ||
print(arr[i]) | ||
sum = sum + arr[i] | ||
end | ||
return sum, arr | ||
]] | ||
) | ||
|
||
assert(f and type(f) == 'function') | ||
local s,arr = f() | ||
assert(s == 18) | ||
assert(arr[0] == 10) | ||
assert(arr[4] == 2) | ||
assert(arr[11] == 6) | ||
assert(#arr == 11) |
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,30 @@ | ||
local sieve = compiler.load([[ | ||
local i: integer, k: integer, prime: integer, count: integer | ||
local flags: integer[] = table.intarray(8190) | ||
for iter=0,100000 do | ||
count = 0 | ||
for i=0,8190 do | ||
flags[i] = 1 | ||
end | ||
for i=0,8190 do | ||
if flags[i] == 1 then | ||
prime = i + i + 3; | ||
for k = i + prime, 8190, prime do | ||
flags[k] = 0 | ||
end | ||
count = count + 1 | ||
end | ||
end | ||
end | ||
return count | ||
]] | ||
) | ||
assert(sieve and type(sieve) == 'function') | ||
|
||
local t1 = os.clock() | ||
local count = sieve() | ||
local t2 = os.clock() | ||
print("time taken ", t2-t1) | ||
print(count) | ||
assert(count == 1899) |