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
local DOUBLE_IEEE_ACCURACY = 1e-8 | |
local function areFuzzyEqual(a, b, accuracy) | |
return (math.abs(a-b) < (accuracy or DOUBLE_IEEE_ACCURACY)) | |
end | |
local function derivative(f, x0, accuracy) | |
local h = 0.1 | |
local xL, xR = x0 - h, x0 + h | |
local tAccr = (f(xR) - f(xL))/(2*h) |
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
print(package.path:gsub(';','\n')) | |
require ('iuplua') | |
iup.Message('Hello', 'Hello from IUPLua') |
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
local Inventory = {} | |
Inventory.__index = Inventory | |
function Inventory:new() | |
local new_inventory = {} | |
new_inventory.items = {} | |
setmetatable(new_inventory, Inventory) | |
return new_inventory | |
end |
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
-- Evaluates times | |
local function time(nm,times, f,...) | |
local st = os.clock() | |
for i = 1, times do | |
f(...) | |
end | |
local et = os.clock() | |
print(('(%s): Times (%d): %.2f ms') | |
:format(nm, times, (et-st)*1000)) | |
end |
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
-- Calls f(...) n-times | |
local function time(nm,times, f,...) | |
local st = os.clock() | |
for i = 1, times do | |
f(...) | |
end | |
local et = os.clock() | |
print(('(%s): Times (%d): %.2f ms') | |
:format(nm, times, (et-st)*1000)) | |
end |
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
-- A stress test for the pathfinding library Jumper (v1.8.1) | |
-- Source: https://github.com/Yonaba/Jumper/tree/jumper-1.8.1-1 | |
-- The purpose of this is to compare the relative performance of different | |
-- search algorithms implemented in Jumper. Time measurements uses Lua's | |
-- native os.clock with (milliseconds precision). | |
-- Library setup | |
local Grid = require 'jumper.grid' |
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
--[[Improved A-Star Pathfinding Algorithm | |
Ported to by Roland Yonaba - aka SeanPaul223 | |
28/01/2010]] | |
--Looks for a node listed in a table of nodes. | |
--Returns true on success, plus the index where it was found. | |
--Otherwise returns false plus nil. | |
function isListed(list,node) | |
local bool,pos | |
bool = false |
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
-- Gauss Seidel Algorithm implemented through lua | |
function Norm(m) | |
local n = 0 | |
for i,v in ipairs(m) do | |
n = n + v^2 | |
end | |
return math.sqrt(n) | |
end |
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
-- SOR Algorithm Implemented through Lua | |
function Norm(m) | |
local n = 0 | |
for i,v in ipairs(m) do | |
n = n + v^2 | |
end | |
return math.sqrt(n) | |
end |
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
-- SOR Algorithm implemented through Lua | |
function Normalize(m) | |
local n = 0 | |
for i,v in ipairs(m) do | |
n = n + v^2 | |
end | |
return math.sqrt(n) | |
end |
NewerOlder