Z26637

{
    "Z1K1": "Z2",
    "Z2K1": {
        "Z1K1": "Z6",
        "Z6K1": "Z26637"
    },
    "Z2K2": {
        "Z1K1": "Z14",
        "Z14K1": "Z26629",
        "Z14K3": {
            "Z1K1": "Z16",
            "Z16K1": "Z600",
            "Z16K2": "function Z26629( Z26629K1 ) {\n\tfunction convertBengaliNumerals(str) {\n        const bengaliNumerals = ['০', '১', '২', '৩', '৪', '৫', '৬', '৭', '৮', '৯'];\n        const arabicNumerals = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];\n        let newStr = str;\n        for (let i = 0; i \u003C 10; i++) {\n            newStr = newStr.replaceAll(bengaliNumerals[i], arabicNumerals[i]);\n        }\n        return newStr;\n    }\n    \n\tvar input=convertBengaliNumerals(Z26629K1);\n\tconst separators=[\" \",\"\\t\",\"/\",\"\\\\\",\":\",\".\",\"|\"];\n\tconst prefOptions=[\"aqhnms\", \"qhnmsa\", \"qhanms\", \"aps\",\"psa\",\"pas\"];\n\n\tfunction languageSpecificOptions(){\n\t\t//phrases\n\t\tdefineLiterals({\n\t\t\t\"দেড়টা\": [1,30],\n\t\t\t\"আড়াইটা\" : [2,30]\n\t\t\t\n\t\t},PHRASE,NORMAL);\n\t\t\n\t\tdefineLiterals({\n\t\t\t\"পোনে\": -15,\n\t\t\t\"পনে\": -15,\n\t\t\t\"সাড়ে\": 30,\n\t\t\t\"সোয়া\":15,\n\t\t\t\"সুয়া\":15,\n\t\t},LITERAL_MINUTE,NORMAL);\n\t\t\n\t\tdefineLiterals({\n\t\t\t\"বাজতে\" : -1,\n\t\t},NEGATIVE,NORMAL);\n\t\t\n\t\tdefineLiterals({\n\t\t\tam:AM,\n\t\t\tpm:PM,\n\t\t\ta:AM,\n\t\t\tp:PM,\n\t\t\t\"㏂\":AM,\n\t\t\t\"㏘\":PM,\n\t\t\t\n\t\t\t\n            \"এএম\": AM,\n            \"এম\": AM,\n            \"পিএম\": PM,\n            \"পি এম\": PM,\n            \n            \n            \"ভোর\": AM,\n            \"সকাল\": AM,\n            \"প্রভাত\": AM,\n            \"পূর্বাহ্ণ\":AM,\n            \n            \n            \"দুপুর\": PM,\n            \"মধ্যাহ্ন\": PM,\n            \"অপরাহ্ণ\": PM,\n            \"বিকাল\": PM,\n            \"সন্ধ্যা\": PM,\n            \"গোধূলি\": PM,\n       \n    \t\t\"রাত\": NIGHT,\n    \t\t\"নিশি\": NIGHT,\n    \t\t\"রাত্রি\":NIGHT,\n\t\t},AMPM,LETTER_BY_LETTER);\n\t\t\n\t\t\n        defineLiterals({\n            \"দুপুর\": 12,\n            \"মধ্যাহ্ন\": 12,\n            \"মধ্যরাত\": 0,\n        }, HOUR, NORMAL);\n        \n        \n        defineConstraint([\"টা\", \"টায়\", \"বেজে\"], HOUR, AFTER);\n        defineConstraint([\"মিনিট\"], MINUTE, AFTER);\n        defineConstraint([\"সেকেন্ড\"], SECOND, AFTER);\n\t}\n\t\n\tfunction formatOutput(o){\n\t\tlet h= o[HOUR]??0;\n\t\tlet m= o[MINUTE]??0;\n\t\t\n\t\tif (o[PHRASE]!=null){\n\t\t\t[h,m]=o[PHRASE];\n\t\t}\n\t\t\n\t\tif (o[AMPM]==AM \u0026\u0026 h==12){\n\t\t\th=0;\n\t\t} else if (o[AMPM]==PM \u0026\u0026 h!=12){\n\t\t\th+=12;\n\t\t} else if (o[AMPM]==NIGHT){\n\t\t\tif (h \u003E= 9 \u0026\u0026 h \u003C= 11) {\n                h = h + 12;\n            } else if (h === 12) {\n                h = 0;\n            }\n\t\t}\n\t\t\n\t\tif (o[LITERAL_MINUTE]!=null){\n\t\t\tif (o[LITERAL_MINUTE]\u003C0){\n\t\t\t\th = (h === 0) ? 23 : h - 1;\n\t\t\t\tm=60+o[LITERAL_MINUTE];\n\t\t\t} else {\n\t\t\t\tm=o[LITERAL_MINUTE];\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\tif(o[NEGATIVE]!=null){\n\t\t\th = (h === 0) ? 23 : h - 1;\n\t\t\tm=60-m;\n\t\t}\n\t\t\n\t\t\n\t\tif (h==24) h=0;\n\t\treturn {K1:h, K2: m, K3: o[SECOND]??0};\n\t}\n\n\n\t//IMPORTANT: delete_chain must contain all the fields\n\tconst delete_chain=\"nqpsmah\";\n\n\t// FIELDS\n\tconst HOUR='h';\n\tconst MINUTE='m';\n\tconst SECOND='s';\n\tconst AMPM='a';\n\tconst PHRASE='p';\n\tconst LITERAL_MINUTE='q';\n\tconst NEGATIVE='n';\n\n\t// SPECIAL VALUES\n\tconst AM=Symbol();\n\tconst PM=Symbol();\n\tconst NIGHT=Symbol();\n\n\t// NUMERIC ELEMENTS SETTINGS\n\tconst numericElements=\"hms\";\n\tconst numericElementMin={\n\t\th:0,\n\t\tm:0,\n\t\ts:0\n\t};\n\tconst numericElementMax={\n\t\th:24,\n\t\tm:59,\n\t\ts:60\t//for leap seconds\n\t}\n\n\t//END OF LANGUAGE-SPECIFIC CODE\n\t\n\t//Start of general code\n\tconst BEFORE=10;\n\tconst AFTER=20;\n\tconst BEFORE_OR_AFTER=30;\n\n\tconst LENIENT=true;\n\tconst NORMAL=false;\n\tconst LETTER_BY_LETTER=Symbol();\n\n\tfunction defineLiterals(literals,meaning,compMode=LENIENT, forced=false){\n\t\tlet bestGuess=null;\n\t\tconst compFunc= compMode==LENIENT ? lenientComp : lessLenientComp;\n\t\tfor (let m in literals){\n\t\t\tlet target=m.split(\" \");\n\t\t\tlet ok=true;\n\t\t\tfor (let t=0; t\u003Ctarget.length; ++t){\n\t\t\t\tif (elements[iAtt+t]==undefined || !compFunc(elements[iAtt+t],target[t])){\n\t\t\t\t\tok=false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (ok){\n\t\t\t\tif (bestGuess == null || bestGuess[1]\u003Ctarget.length){\n\t\t\t\t\tbestGuess = [literals[m],target.length];\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (compMode==LETTER_BY_LETTER ){\n\t\t\t\tlet target=m.split(\"\");\n\t\t\t\ttarget.filter((l)=\u003El!=\" \");\n\t\t\t\tlet ok=true;\n\t\t\t\tfor (let t=0; t\u003Ctarget.length; ++t){\n\t\t\t\t\tif (elements[iAtt+t]==undefined || !compFunc(elements[iAtt+t],target[t])){\n\t\t\t\t\t\tok=false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (ok){\n\t\t\t\t\tif (bestGuess == null || bestGuess[1]\u003Ctarget.length){\n\t\t\t\t\t\tbestGuess = [literals[m],target.length];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t}\n\t\tif (bestGuess==null){\n\t\t\treturn false;\n\t\t}\n\n\t\tif (typeof(meaning)==\"string\"){\n\t\t\tmeaning=[meaning];\n\t\t}\n\t\tfor (let m of meaning){\n\t\t\t_currGuess[m]=bestGuess[0];\n\t\t}\n\t\t_nSteps=bestGuess[1];\n\t\tif (forced){\n\t\t\t_forced=meaning;\n\t\t}\n\t\treturn true;\n\n\t}\n\tfunction defineLiteralFunction(f,meaning, forced=false){\n\t\tlet bestGuess=f(elements,iAtt);\n\t\tif (bestGuess==null){\n\t\t\treturn false;\n\t\t}\n\n\t\tif (typeof(meaning)==\"string\"){\n\t\t\tmeaning=[meaning];\n\t\t}\n\t\tfor (let m of meaning){\n\t\t\t_currGuess[m]=bestGuess[0];\n\t\t}\n\t\t_nSteps=bestGuess[1];\n\t\tif (forced){\n\t\t\t_forced=meaning;\n\t\t}\n\t\treturn true;\n\t}\n\tfunction defineConstraint(literals, meaning, position, compMode=NORMAL){\n\n\t\tlet bestGuess=null;\n\t\tconst compFunc= compMode==LENIENT ? lenientComp : lessLenientComp;\n\t\tfor (let m of literals){\n\t\t\tlet target=m.split(\" \");\n\t\t\tlet ok=true;\n\t\t\tfor (let t=0; t\u003Ctarget.length; ++t){\n\t\t\t\tif (elements[iAtt+t]==undefined || !compFunc(elements[iAtt+t],target[t])){\n\t\t\t\t\tok=false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (ok){\n\t\t\t\tif (bestGuess == null || bestGuess\u003Ctarget.length){\n\t\t\t\t\tbestGuess = target.length;\n\t\t\t\t}\n\t\t\t}\n\n\t\t}\n\t\tif (bestGuess==null){\n\t\t\treturn false;\n\t\t}\n\t\t\n\n\t\tif (typeof(meaning)==\"string\"){\n\t\t\tmeaning=[meaning];\n\t\t}\n\t\t\n\t\t_constraintsList.push({pos:possibilities.length, meaning:meaning, type: position});\n\n\t\t_nSteps=bestGuess;\n\t\t_isToBeIgnored=true;\n\t\treturn true;\n\t}\n\tfunction defineConstraintFunction(f,meaning,position){\n\n\t\tlet bestGuess=f(elements,iAtt);\n\t\tif (bestGuess==null){\n\t\t\treturn false;\n\t\t}\n\n\t\tif (typeof(meaning)==\"string\"){\n\t\t\tmeaning=[meaning];\n\t\t}\n\t\t_constraintsList.push({pos:possibilities.length, meaning:meaning, type: position});\n\t\t_nSteps=bestGuess;\n\t\t_isToBeIgnored=true;\n\t\treturn true;\n\t}\n\n\tfunction lenientComp(a,b){\n\t\ta=a.toLowerCase().replaceAll(/,|\\.|;|:/g,\"\");\n\t\tb=b.toLowerCase();\n\t\tif (a==\"\") return false;\n\t\treturn a==b.substring(0,a.length);\n\t}\n\n\tfunction lessLenientComp(a,b){\n\t\ta=a.toLowerCase().replaceAll(/,|\\.|;|:/g,\"\");\n\t\tb=b.toLowerCase();\n\t\tif (a==\"\") return false;\n\t\treturn a==b;\n\t}\n\n\tfunction extractNumber(s){\n\t\tlet res=/-?[0-9]+/.exec(s);\n\t\tif (res!=null){\n\t\t\treturn Number(res);\n\t\t}\n\t\treturn null;\n\t}\n\n\n\n\t\n\t/**************** START TOKENISATION ***********************/\n\n\tinput=input.replaceAll(/-|—|‒|–|—|⸺|⸺/g,\"-\");\n\n\n\tvar elements=[\"\"];\n\tfor (let i=0; i\u003Cinput.length;){\n\t\tlet s=separators.find((v)=\u003E input.substring(i,i+v.length)==v);\n\t\tif (s!==undefined){\n\t\t\tif(elements[elements.length-1]!=\"\")\n\t\t\t\telements.push(\"\");\n\t\t\ti+=s.length;\n\t\t\tcontinue;\n\t\t}\n\t\telements[elements.length-1]+=input[i++];\n\t}\n\tif(elements[elements.length-1]==\"\") elements.pop();\n\n\n\tlet elSeparato=[];\n\tfor (let i=0; i\u003Celements.length; ++i){\n\t\t//Separate numbers from text\n\t\tfor (let e of elements[i].matchAll(/((?:(?\u003C=^|\\s)[\\-\\+])?[0-9]+)?(?:\\-?([^0-9\\-]+))?/g)){\n\t\t\telSeparato.push(e.splice(1))\n\t\t}\n\t}\n\telSeparato=elSeparato.flat();\n\telements=elSeparato.filter((v)=\u003E(v!=null \u0026\u0026 v!=\"\"));\n\n\t// Wikifunctions.Debug(\"elements:\");\n\t// Wikifunctions.Debug(elements);\n\n\t/**************** END TOKENISATION ***********************/\n\t/**************** START FINDING POSSIBILITIES ***********************/\n\tvar possibilities=[];\n\n\tvar _constraintsList=[];\n\tvar _nSteps=1;\n\n\tfor(var iAtt=0; iAtt\u003Celements.length; iAtt+=_nSteps){\n\t\t_nSteps=1;\n\t\tlet n=extractNumber(elements[iAtt]);\n\t\tvar _currGuess={};\t//Object containing all the current guesses\n\t\tvar _forced=null;\n\t\tvar _isToBeIgnored=false;\n\n\t\t//////////\n\n\t\tlanguageSpecificOptions();\n\n\t\tfor (let i of numericElements){\n\t\t\tif (n\u003E=numericElementMin[i] \u0026\u0026 n\u003C=numericElementMax[i]){\n\t\t\t\t_currGuess[i]??=n;\n\t\t\t}\n\t\t}\n\n\n\n\t\tif (_forced!=null){\n\t\t\tfor (let j in _currGuess){\n\t\t\t\tif (_forced.find((v)=\u003E(v==j)) == undefined){\n\t\t\t\t\t_currGuess[j]=null;\t\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (!_isToBeIgnored)\n\t\t\tpossibilities.push(_currGuess);\n\t}\n\t\n\n\tif (_constraintsList.length\u003E0){\n\t\tfor (let pAtt=0; pAtt\u003C possibilities.length; ++pAtt){\n\t\t\tfor (let c of _constraintsList){\n\t\t\t\tif ((c.type==AFTER \u0026\u0026 pAtt!=c.pos-1) ||\n\t\t\t\t    (c.type==BEFORE \u0026\u0026 pAtt!=c.pos) ||\n\t\t\t\t    (c.type==BEFORE_OR_AFTER \u0026\u0026 pAtt!=c.pos-1 \u0026\u0026 pAtt!=c.pos)){\n\t\t\t\t\tfor(let m of c.meaning){\n\t\t\t\t\t\tpossibilities[pAtt][m]=null;\t\n\t\t\t\t\t}\n\t\t\t\t} else if ((c.type==AFTER \u0026\u0026 pAtt==c.pos-1) ||\n\t\t\t\t\t(c.type==BEFORE \u0026\u0026 pAtt==c.pos)){\n\t\t\t\t\tfor (let m in possibilities[pAtt]){\n\t\t\t\t\t\tif (c.meaning.find((x)=\u003E x==m)==undefined){\n\t\t\t\t\t\t\tpossibilities[pAtt][m]=null;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t/**************** END FINDING POSSIBILITIES ***********************/\n\n\n\tpossibilities=possibilities.filter((v)=\u003E(Object.entries(v).filter((x)=\u003Ex[1]!=null).length\u003E0));\n\n\t//remove elements that are not present\n\tlet lettersToRemove=\"\";\n\tif(delete_chain.length\u003Epossibilities.length){\n\t\tfor (let i of delete_chain){\n\t\t\tif (possibilities.find((p)=\u003Ep[i]!=null)==undefined){\n\t\t\t\tlettersToRemove+=i;\n\t\t\t}\n\t\t}\n\t}\n\n\t//save tokens that have only one possibility\n\tlet safeLetters=\"\";\n\tif(delete_chain.length\u003Epossibilities.length){\n\t\tfor (let p of possibilities){\n\t\t\tif (Object.entries(p).filter((x)=\u003Ex[1]!=null).length ==1){\n\t\t\t\tsafeLetters+=Object.entries(p).filter((x)=\u003Ex[1]!=null)[0][0];\n\t\t\t}\n\t\t}\n\t}\n\n\n\n\t//remove elements according to the deletion chain\n\tfor(let i=0; delete_chain.length-lettersToRemove.length\u003Epossibilities.length \u0026\u0026 i\u003Cdelete_chain.length; ++i){\n\t\tif (lettersToRemove.indexOf(delete_chain[i])== -1 \u0026\u0026 safeLetters.indexOf(delete_chain[i])==-1){\n\t\t\tlettersToRemove+= delete_chain[i];\n\t\t}\n\t}\n\t\t/**************** CHECK OF ALL ORDERS ***********************/\n\t\n\tfor (let i=0; i\u003CprefOptions.length; ++i){\n\t\tlet actPref=prefOptions[i];\n\t\tlet elementsFound={};\n\t\t\n\t\tfor (let l of lettersToRemove){\n\t\t\tactPref=actPref.replace(l,\"\");\n\t\t}\n\t\t\n\t\tlet ok=true;\n\t\tfor (let j=0; j\u003CactPref.length; ++j){\n\t\t\telementsFound[actPref[j]]=possibilities[j]?.[actPref[j]];\n\t\t\tif (elementsFound[actPref[j]] == null){\n\t\t\t\tok=false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tfor (let f of safeLetters){\n\t\t\tif (elementsFound[f]==null){\n\t\t\t\tok=false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (ok){\n\t\t\treturn formatOutput(elementsFound);\t\n\t\t}\n\t}\n\n\n}"
        }
    },
    "Z2K3": {
        "Z1K1": "Z12",
        "Z12K1": [
            "Z11",
            {
                "Z1K1": "Z11",
                "Z11K1": "Z1787",
                "Z11K2": "leggi Orario, bengalese, usando solo API"
            },
            {
                "Z1K1": "Z11",
                "Z11K1": "Z1002",
                "Z11K2": "read Time of day, Bangla, using only APIs"
            }
        ]
    },
    "Z2K4": {
        "Z1K1": "Z32",
        "Z32K1": [
            "Z31"
        ]
    },
    "Z2K5": {
        "Z1K1": "Z12",
        "Z12K1": [
            "Z11",
            {
                "Z1K1": "Z11",
                "Z11K1": "Z1002",
                "Z11K2": "Rewriting of Z26632 using only the API provided by the language-generic code"
            }
        ]
    }
}