beyler bu bini lua da ben kodladım. ahanda kaynak kodları
==
Set = {}
Set.mt = {}
function Set.mt.__add (a,b)
local res = Set.new{}
for k in pairs(a) do res[k] = true end
for k in pairs(b) do res[k] = true end
return res
end
function Set.mt.__mul (a,b)
local res = Set.new{}
for k in pairs(a) do
res[k] = b[k]
end
return res
end
function Set.mt.__le (a,b)
for k in pairs(a) do
if not b[k] then return false end
end
return true
end
function Set.mt.__lt (a,b)
return a <= b and not (b <= a)
end
function Set.mt.__eq (a,b)
return a <= b and b <= a
end
function Set.mt.__tostring (set)
local s = "{"
local sep = ""
for e in pairs(set) do
s = s .. sep .. e
sep = ", "
end
return s .. "}"
end
function Set.new (t)
local set = {}
setmetatable(set, Set.mt)
for _, l in ipairs(t) do set[l] = true end
return set
end
s1 = Set.new{nickime bakan herkesin anasını siqtim ;)}
s2 = Set.new{nickime bakan herkes anamı siqti ;(}
s3 = s1 + s2
print(s3) --> {10, 30, 20, 1, 50}
print((s1 + s2)*s1) --> {10, 20, 30, 50}
s1 = Set.new{2, 4}
s2 = Set.new{4, 10, 2}
print(s1 <= s2) --> true
print(s1 < s2) --> true
print(s1 >= s1) --> true
print(s1 > s1) --> false
print(s1 == s2 * s1) --> truefunction eraseTerminal ()
io.write("27[2J")
end
-- writes an
* at columnx' , row `y'
function mark (x,y)
io.write(string. format("27[%d;%dH*", y, x))
end
-- Terminal size
TermSize = {w = 80, h = 24}
-- plot a function
-- (assume that domain and image are in the range [-1,1])
function plot (f)
eraseTerminal()
for i=1,TermSize.w do
local x = (i/TermSize.w)*2 - 1
local y = (f(x) + 1)/2 * TermSize.h
mark(i, y)
end
io.read() -- wait before spoiling the screen
end
function permgen (a, n)
if n == 0 then
coroutine. yield(a)
else
for i=1,n do
-- put i-th element as the last one
a[n], a[i] = a[i], a[n]
-- generate all permutations of the other elements
permgen(a, n - 1)
-- restore i-th element
a[n], a[i] = a[i], a[n]
end
end
end
function perm (a)
local n = table. getn(a)
return coroutine. wrap(function () permgen(a, n) end)
end
function printResult (a)
for i,v in ipairs(a) do
io.write(v, " ")
end
io.write("n")
end
for p in perm{"a", "b", "c"} do
printResult(p)
end
plot(function (x) return math.sin(x*2*math.pi) end)
==