Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,23 @@
function Transpose( m )
local res = {}
for i = 1, #m[1] do
res[i] = {}
for j = 1, #m do
res[i][j] = m[j][i]
end
end
return res
end
-- a test for Transpose(m)
mat = { { 1, 2, 3 }, { 4, 5, 6 } }
erg = Transpose( mat )
for i = 1, #erg do
for j = 1, #erg[1] do
io.write( erg[i][j] )
io.write( " " )
end
io.write( "\n" )
end

View file

@ -0,0 +1,27 @@
function map(f, a)
local b = {}
for k,v in ipairs(a) do b[k] = f(v) end
return b
end
function mapn(f, ...)
local c = {}
local k = 1
local aarg = {...}
local n = #aarg
while true do
local a = map(function(b) return b[k] end, aarg)
if #a < n then return c end
c[k] = f(unpack(a))
k = k + 1
end
end
function apply(f1, f2, a)
return f1(f2, unpack(a))
end
xy = {{1,2,3,4},{1,2,3,4},{1,2,3,4}}
yx = apply(mapn, function(...) return {...} end, xy)
print(table.concat(map(function(a) return table.concat(a,",") end, xy), "\n"),"\n")
print(table.concat(map(function(a) return table.concat(a,",") end, yx), "\n"))