אונטערשייד צווישן ווערסיעס פון "יחידה:גימטריה"

264 בייטן צוגעלייגט ,  פֿאַר 7 חדשים
מספר לאותיות function should output ה'תשס"ו for 5766, not תתתתתתתתתתתתתתקסו
(אימפארטירט פון די העברישע המכלול, זע ביישטייערער ליסטע)
 
(מספר לאותיות function should output ה'תשס"ו for 5766, not תתתתתתתתתתתתתתקסו)
 
(2 צווישנדיגע ווערסיעס פונעם זעלבן באַניצער נישט געוויזן)
שורה 36: שורה 36:


local gimatria = function(s)
local gimatria = function(s)
         local sum = 0
    -- Check for a thousands separator (apostrophe)
         for l in mw.ustring.gmatch( s, "." ) do sum = sum + ( values[l] or endet[l] or 0) end
    local thousands, rest = s:match("^(.-)'(.*)$")
         return sum
    if thousands and rest ~= "" then
        local total = 0
         local thousandsValue = 0
        -- Calculate gematria for the thousands part
        for l in mw.ustring.gmatch(thousands, ".") do
            thousandsValue = thousandsValue + (values[l] or endet[l] or 0)
        end
        total = thousandsValue * 1000
        -- Add gematria for the rest of the number (ignoring extra apostrophes)
        for l in mw.ustring.gmatch(rest, ".") do
            total = total + (values[l] or endet[l] or 0)
        end
        return total
    else
        local total = 0
         for l in mw.ustring.gmatch(s, ".") do
            total = total + (values[l] or endet[l] or 0)
        end
         return total
    end
end
end


local mispar_lotiot = function( num, geresh )
local mispar_lotiot = function(num, geresh)
        local res, toadd = '', 0
    local res = ''
         while num > 0 do
 
            if num >= 400 then toadd = 400
    -- Handle thousands
            elseif num >= 100 then toadd = num - num % 100
    local thousands = math.floor(num / 1000)
            elseif num >= 10 then toadd = num - num % 10
    local remainder = num % 1000
            else toadd = num end
 
             res = res .. tab[toadd]
    if thousands > 0 then
            num = num - toadd
         res = res .. tab[thousands] .. "'"
    end
 
    local n = remainder
    while n > 0 do
        local toadd = 0
        if n >= 400 then
            toadd = 400
        elseif n >= 100 then
            toadd = n - n % 100
        elseif n >= 10 then
            toadd = n - n % 10
        else
             toadd = n
         end
         end
         res = mw.ustring.gsub( res, 'יה', 'טו' )
         res = res .. tab[toadd]
        res = mw.ustring.gsub( res, 'יו', 'טז' )
        n = n - toadd
         res = mw.ustring.gsub( res, '(.)(.)$', '%1' .. (geresh or '') .. '%2' )
    end
         return res
 
    -- Special case for 15 and 16
    res = mw.ustring.gsub(res, 'יה', 'טו')
    res = mw.ustring.gsub(res, 'יו', 'טז')
 
    -- Add geresh or gershayim if needed
    if mw.ustring.len(res) > 1 then
         res = mw.ustring.gsub(res, '(.)(.)$', '%1' .. (geresh or '"') .. '%2')
    else
         res = res .. (geresh or "'")
    end
 
    return res
end
end


שורה 74: שורה 118:
     ['מספר לאותיות'] = function( frame )
     ['מספר לאותיות'] = function( frame )
         return mispar_lotiot( (tonumber(frame.args[1]) or 0),  ( frame.args[2] or '' ))
         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,
     end,
}
}