יחידה:גימטריה
מען קען שאפן דאקומענטאציע פאר דעם מאדול ביי יחידה:גימטריה/דאק
local values = {
['א'] = 1,
['ב'] = 2,
['ג'] = 3,
['ד'] = 4,
['ה'] = 5,
['ו'] = 6,
['ז'] = 7,
['ח'] = 8,
['ט'] = 9,
['י'] = 10,
['כ'] = 20,
['ל'] = 30,
['מ'] = 40,
['נ'] = 50,
['ס'] = 60,
['ע'] = 70,
['פ'] = 80,
['צ'] = 90,
['ק'] = 100,
['ר'] = 200,
['ש'] = 300,
['ת'] = 400,
}
local tab = {}
for k, v in pairs( values ) do tab[v] = k end
local endet = {
['ך'] = 20,
['ם'] = 40,
['ן'] = 50,
['ף'] = 80,
['ץ'] = 90,
}
local gimatria = function(s)
local sum = 0
for l in mw.ustring.gmatch( s, "." ) do sum = sum + ( values[l] or endet[l] or 0) end
return sum
end
local mispar_lotiot = function( num, geresh )
local res, toadd = '', 0
while num > 0 do
if num >= 400 then toadd = 400
elseif num >= 100 then toadd = num - num % 100
elseif num >= 10 then toadd = num - num % 10
else toadd = num end
res = res .. tab[toadd]
num = num - toadd
end
res = mw.ustring.gsub( res, 'יה', 'טו' )
res = mw.ustring.gsub( res, 'יו', 'טז' )
res = mw.ustring.gsub( res, '(.)(.)$', '%1' .. (geresh or '') .. '%2' )
return res
end
local haba = function(s)
return mispar_lotiot(gimatria(s)+1, '')
end
local haqodem = function(s)
return mispar_lotiot(gimatria(s)-1, '')
end
return {
gimatria = gimatria,
['גימטריה'] = function( frame )
return gimatria(frame.args[1] or '')
end,
mispar_lotiot = mispar_lotiot,
['מספר לאותיות'] = function( frame )
return mispar_lotiot( (tonumber(frame.args[1]) or 0), ( frame.args[2] or '' ))
end,
haba = haba,
['הבא'] = function( frame )
local args = frame.args;
if args[1] == nil then
local parent = frame:getParent();
args = parent.args;
end
return haba(args[1] or '')
end,
haqodem = haqodem,
['הקודם'] = function( frame )
local args = frame.args;
if args[1] == nil then
local parent = frame:getParent();
args = parent.args;
end
return haqodem(args[1] or '')
end,
['שנה'] = function( frame )
local args = frame.args;
if args[1] == nil then
local parent = frame:getParent();
args = parent.args;
end
return gimatria(args[1] or '')*1000 + gimatria(args[2] or '')
end,
}