Modul:Mergesort: Unterschied zwischen den Versionen

Aus KGS-Wiki
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 5: Zeile 5:
for i = 1,8,1 do
for i = 1,8,1 do
res[i] = math.random(99)
res[i] = math.random(99)
end
return res
end
function tableToString(t,from,to)
local res = ''
for i = from,to do
res = res .. t[i]
if i < to then
res = res .. ' '
end
end
end
return res
return res
Zeile 14: Zeile 25:
local content = 'graph TD\n'
local content = 'graph TD\n'
content = content .. 'subgraph divide\n'
content = content .. 'subgraph divide\n'
content = content .. 'a[' .. unpack(l,1,8) .. ']\n'
content = content .. 'a[' .. tableToString(l,1,8) .. ']\n'
--content = content .. 'a --> b[' .. a .. ' ' .. b .. ' ' .. c .. ' ' .. d .. '] & c[' .. e .. ' ' .. f .. ' ' .. g .. ' ' .. h .. ']\n'
--content = content .. 'a --> b[' .. a .. ' ' .. b .. ' ' .. c .. ' ' .. d .. '] & c[' .. e .. ' ' .. f .. ' ' .. g .. ' ' .. h .. ']\n'
--content = content .. 'b --> d[' .. a .. ' ' .. b .. '] & e[' .. c .. ' ' .. d .. ']\n'
--content = content .. 'b --> d[' .. a .. ' ' .. b .. '] & e[' .. c .. ' ' .. d .. ']\n'
Zeile 40: Zeile 51:
content = content .. 'end'
content = content .. 'end'
local graph = frame:extensionTag('mermaid', content, {})
local graph = frame:extensionTag('mermaid', content, {})
return unpack(l,1,8)
return graph
end
end


return p
return p

Version vom 3. Juni 2024, 10:56 Uhr

Die Dokumentation für dieses Modul kann unter Modul:Mergesort/Doku erstellt werden

local p = {}

function createRandomList()
	local res = {}
	for i = 1,8,1 do
		res[i] = math.random(99)
	end
	return res
end

function tableToString(t,from,to)
	local res = ''
	for i = from,to do
		res = res .. t[i]
		if i < to then
			res = res .. ' '
		end
	end
	return res
end

function p.example()
	local l = createRandomList()
	frame = mw.getCurrentFrame()
	local content = 'graph TD\n'
	content = content .. 'subgraph divide\n'
	content = content .. 'a[' .. tableToString(l,1,8) .. ']\n'
	--content = content .. 'a --> b[' .. a .. ' ' .. b .. ' ' .. c .. ' ' .. d .. '] & c[' .. e .. ' ' .. f .. ' ' .. g .. ' ' .. h .. ']\n'
	--content = content .. 'b --> d[' .. a .. ' ' .. b .. '] & e[' .. c .. ' ' .. d .. ']\n'
	--content = content .. 'c --> f[' .. e .. ' ' .. f .. '] & g[' .. g .. ' ' .. h .. ']\n'
	--content = content .. 'd --> h[' .. a .. '] & i[' .. b .. ']\n'
	--content = content .. 'e --> j[' .. c .. '] & k[' .. d .. ']\n'
	--content = content .. 'f --> l[' .. e .. '] & m[' .. f .. ']\n'
	--content = content .. 'g --> n[' .. g .. '] & o[' .. h .. ']\n'
	content = content .. 'end\n'
	content = content .. 'subgraph conquer\n'
	--h --> p["{{#af_join:{{#af_sort:{{#af_list:{{{1|94}}} | {{{2|73}}}}}}}|&nbsp;}}"]
	--i --> p
	--j --> q["{{#af_join:{{#af_sort:{{#af_list:{{{3|58}}} | {{{4|61}}}}}}}|&nbsp;}}"]
	--k --> q
	--l --> r["{{#af_join:{{#af_sort:{{#af_list:{{{5|22}}} | {{{6|20}}}}}}}|&nbsp;}}"]
	--m --> r
	--n --> s["{{#af_join:{{#af_sort:{{#af_list:{{{7|46}}} | {{{8|75}}}}}}}|&nbsp;}}"]
	--o --> s
	--p --> t["{{#af_join:{{#af_sort:{{#af_list:{{{3|58}}} | {{{4|61}}} | {{{2|73}}} | {{{1|94}}}}}}}|&nbsp;}}"]
	--q --> t
	--r --> u["{{#af_join:{{#af_sort:{{#af_list:{{{6|20}}} | {{{5|22}}} | {{{7|46}}} | {{{8|75}}}}}}}|&nbsp;}}"]
	--s --> u
	--t --> v["{{#af_join:{{#af_sort:{{#af_list:{{{6|20}}} | {{{5|22}}} | {{{7|46}}} | {{{3|58}}} | {{{4|61}}} | {{{2|73}}} | {{{8|75}}} | {{{1|94}}}}}}}|&nbsp;}}"]
	--u --> v
	content = content .. 'end'
local graph = frame:extensionTag('mermaid', content, {})
return graph
end

return p