From bd6e463a3cbb8925733d5dcd7e635fa47a739747 Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Wed, 7 Sep 2022 13:53:59 +0800 Subject: [PATCH 1/5] fix #35 --- homo.js | 1 + 1 file changed, 1 insertion(+) diff --git a/homo.js b/homo.js index b47e513..5313cdc 100644 --- a/homo.js +++ b/homo.js @@ -47,6 +47,7 @@ const homo = ((Nums) => { expr = expr.replace(/^\(([^\(\)]+)\)$/, "$1") expr = expr.replace(/\+-/g,'-') + expr = expr.replace(/\*\*/g, "^") return expr } return (num) => finisher(demolish(num)) From e9e6c61277084b6d6f3a8129d497a2a6a07816ce Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Wed, 7 Sep 2022 16:47:25 +0800 Subject: [PATCH 2/5] fix 343542 etc --- homo.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/homo.js b/homo.js index 5313cdc..99cb2b3 100644 --- a/homo.js +++ b/homo.js @@ -25,6 +25,8 @@ const homo = ((Nums) => { if (Nums[num]) return String(num) + if (num % 114514 === 0) + return `(${demolish(num / 114514)})×114514` const div = getMinDiv(num) return (`${div}*(${demolish(Math.floor(num / div))})+` + From 7d704c6386cdfd64342e36f108736f1d2459b228 Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Wed, 7 Sep 2022 16:47:35 +0800 Subject: [PATCH 3/5] little update --- homo.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/homo.js b/homo.js index 99cb2b3..a925750 100644 --- a/homo.js +++ b/homo.js @@ -45,8 +45,7 @@ const homo = ((Nums) => { while (expr.match(/[\+|\-]\(([^\(\)]+)\)$/)) expr = expr.replace(/([\+|\-])\(([^\(\)]+)\)$/, (m, $1, $2) => $1 + $2) //If there is a bracket in the outermost part, remove it - if (expr.match(/^\([^\(\)]+?\)$/)) - expr = expr.replace(/^\(([^\(\)]+)\)$/, "$1") + expr = expr.replace(/^\(([^\(\)]+)\)$/, "$1") expr = expr.replace(/\+-/g,'-') expr = expr.replace(/\*\*/g, "^") From e501d04379249bfe39c00ea3ecd1d52f81b4a0ae Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Wed, 7 Sep 2022 16:55:22 +0800 Subject: [PATCH 4/5] fix #20 `"-([^,]+)"` -> `"(-$1)"` `\*-([^+\-\*/"\(]+)` -> `*(-$1)` `\*-(\([^\)]+\))` -> `*(-$1)` --- homo.js | 266 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 133 insertions(+), 133 deletions(-) diff --git a/homo.js b/homo.js index a925750..43ff35f 100644 --- a/homo.js +++ b/homo.js @@ -64,7 +64,7 @@ const homo = ((Nums) => { 16030: "1145*14", 14515: "1+14514", 14514: "1*14514", - 14513: "-1+14514", + 14513: "(-1+14514)", 11455: "11451+4", 11447: "11451-4", 9028: "(1+1)*4514", @@ -73,20 +73,20 @@ const homo = ((Nums) => { 7710: "(1+14)*514", 7197: "1+14*514", 7196: "1*14*514", - 7195: "-1+14*514", + 7195: "(-1+14*514)", 6930: "11*45*14", - 6682: "(1-14)*-514", + 6682: "(1-14)*(-514)", 6270: "114*(51+4)", 5818: "114*51+4", 5810: "114*51-4", 5808: "(1+1451)*4", 5805: "1+1451*4", 5804: "1*1451*4", - 5803: "-1+1451*4", - 5800: "(1-1451)*-4", + 5803: "(-1+1451*4)", + 5800: "(1-1451)*(-4)", 5725: "1145*(1+4)", 5698: "11*(4+514)", - 5610: "-11*(4-514)", + 5610: "(-11*(4-514))", 5358: "114*(51-4)", 5005: "11*(451+4)", 4965: "11*451+4", @@ -99,21 +99,21 @@ const homo = ((Nums) => { 4516: "1+1+4514", 4515: "1+1*4514", 4514: "1-1+4514", - 4513: "-1*1+4514", - 4512: "-1-1+4514", - 4503: "-11+4514", + 4513: "(-1*1+4514)", + 4512: "(-1-1+4514)", + 4503: "(-11+4514)", 4112: "(1+1)*4*514", 3608: "(1+1)*451*4", 3598: "(11-4)*514", - 3435: "-1145*(1-4)", + 3435: "(-1145*(1-4))", 3080: "11*4*5*14", 3060: "(11+4)*51*4", 2857: "1+14*51*4", 2856: "1*14*51*4", - 2855: "-1+14*51*4", + 2855: "(-1+14*51*4)", 2850: "114*5*(1+4)", 2736: "114*(5+1)*4", - 2652: "(1-14)*51*-4", + 2652: "(1-14)*51*(-4)", 2570: "1*(1+4)*514", 2475: "11*45*(1+4)", 2420: "11*4*(51+4)", @@ -126,15 +126,15 @@ const homo = ((Nums) => { 2058: "1+1+4*514", 2057: "1/1+4*514", 2056: "1/1*4*514", - 2055: "-1/1+4*514", - 2054: "-1-1+4*514", - 2045: "-11+4*514", + 2055: "(-1/1+4*514)", + 2054: "(-1-1+4*514)", + 2045: "(-11+4*514)", 2044: "(1+145)*14", 2031: "1+145*14", 2030: "1*145*14", - 2029: "-1+145*14", + 2029: "(-1+145*14)", 2024: "11*(45+1)*4", - 2016: "-(1-145)*14", + 2016: "(-(1-145)*14)", 1980: "11*45*1*4", 1936: "11*(45-1)*4", 1848: "(11+451)*4", @@ -144,23 +144,23 @@ const homo = ((Nums) => { 1806: "1+1+451*4", 1805: "1+1*451*4", 1804: "1-1+451*4", - 1803: "1*-1+451*4", - 1802: "-1-1+451*4", - 1800: "1*-(1-451)*4", - 1793: "-11+451*4", - 1760: "-(11-451)*4", - 1710: "114*-5*(1-4)", + 1803: "1*(-1)+451*4", + 1802: "(-1-1+451*4)", + 1800: "1*(-(1-451))*4", + 1793: "(-11+451*4)", + 1760: "(-(11-451)*4)", + 1710: "114*(-5)*(1-4)", 1666: "(114+5)*14", 1632: "(1+1)*4*51*4", - 1542: "1*-(1-4)*514", + 1542: "1*(-(1-4))*514", 1526: "(114-5)*14", - 1485: "11*-45*(1-4)", + 1485: "11*(-45)*(1-4)", 1456: "1+1451+4", 1455: "1*1451+4", - 1454: "-1+1451+4", + 1454: "(-1+1451+4)", 1448: "1+1451-4", 1447: "1*1451-4", - 1446: "-1+1451-4", + 1446: "(-1+1451-4)", 1428: "(11-4)*51*4", 1386: "11*(4+5)*14", 1260: "(1+1)*45*14", @@ -176,12 +176,12 @@ const homo = ((Nums) => { 1056: "11*4*(5+1)*4", 1050: "(11+4)*5*14", 1036: "(1+1)*(4+514)", - 1026: "114*-(5-14)", + 1026: "114*(-(5-14))", 1020: "1*(1+4)*51*4", 981: "1+14*5*14", 980: "1*14*5*14", - 979: "-1+14*5*14", - 910: "-(1-14)*5*14", + 979: "(-1+14*5*14)", + 910: "(-(1-14)*5*14)", 906: "(1+1)*451+4", 898: "(1+1)*451-4", 894: "(1+1)*(451-4)", @@ -192,9 +192,9 @@ const homo = ((Nums) => { 818: "1+1+4*51*4", 817: "1*1+4*51*4", 816: "1*1*4*51*4", - 815: "-1+1*4*51*4", - 814: "-1-1+4*51*4", - 805: "-11+4*51*4", + 815: "(-1+1*4*51*4)", + 814: "(-1-1+4*51*4)", + 805: "(-11+4*51*4)", 784: "(11+45)*14", 771: "1+14*(51+4)", 770: "1*14*(51+4)", @@ -203,43 +203,43 @@ const homo = ((Nums) => { 730: "(1+145)*(1+4)", 726: "1+145*(1+4)", 725: "1*145*(1+4)", - 724: "-1-145*-(1+4)", - 720: "(1-145)*-(1+4)", + 724: "(-1-145*(-(1+4)))", + 720: "(1-145)*(-(1+4))", 719: "1+14*51+4", 718: "1*14*51+4", - 717: "-1-14*-51+4", - 715: "(1-14)*-(51+4)", + 717: "(-1-14*(-51)+4)", + 715: "(1-14)*(-(51+4))", 711: "1+14*51-4", 710: "1*14*51-4", - 709: "-1+14*51-4", + 709: "(-1+14*51-4)", 705: "(1+14)*(51-4)", 704: "11*4*(5-1)*4", 688: "114*(5+1)+4", 680: "114*(5+1)-4", - 667: "-(1-14)*51+4", + 667: "(-(1-14)*51+4)", 660: "(114+51)*4", 659: "1+14*(51-4)", 658: "1*14*(51-4)", - 657: "-1+14*(51-4)", + 657: "(-1+14*(51-4))", 649: "11*(45+14)", 644: "1*(1+45)*14", 641: "11+45*14", 632: "1+1+45*14", 631: "1*1+45*14", 630: "1*1*45*14", - 629: "1*-1+45*14", + 629: "1*(-1)+45*14", 628: "114+514", - 619: "-11+45*14", - 616: "1*-(1-45)*14", - 612: "-1*(1-4)*51*4", - 611: "(1-14)*-(51-4)", + 619: "(-11+45*14)", + 616: "1*(-(1-45))*14", + 612: "(-1*(1-4)*51*4)", + 611: "(1-14)*(-(51-4))", 609: "11*(4+51)+4", 601: "11*(4+51)-4", 595: "(114+5)*(1+4)", 584: "114*5+14", 581: "1+145*1*4", 580: "1*145/1*4", - 579: "-1+145*1*4", + 579: "(-1+145*1*4)", 576: "1*(145-1)*4", 575: "114*5+1+4", 574: "114*5/1+4", @@ -254,23 +254,23 @@ const homo = ((Nums) => { 545: "(114-5)*(1+4)", 529: "1+14+514", 528: "1*14+514", - 527: "-1+14+514", + 527: "(-1+14+514)", 522: "(1+1)*4+514", 521: "11-4+514", 520: "1+1+4+514", 519: "1+1*4+514", 518: "1-1+4+514", - 517: "-1+1*4+514", - 516: "-1-1+4+514", + 517: "(-1+1*4+514)", + 516: "(-1-1+4+514)", 514: "(1-1)/4+514", - 513: "-11*(4-51)-4", + 513: "(-11*(4-51)-4)", 512: "1+1-4+514", 511: "1*1-4+514", 510: "1-1-4+514", 509: "11*45+14", - 508: "-1-1-4+514", - 507: "-11+4+514", - 506: "-(1+1)*4+514", + 508: "(-1-1-4+514)", + 507: "(-11+4+514)", + 506: "(-(1+1)*4+514)", 502: "11*(45+1)-4", 501: "1-14+514", 500: "11*45+1+4", @@ -284,33 +284,33 @@ const homo = ((Nums) => { 481: "11*45-14", 480: "11*(45-1)-4", 476: "(114+5)/1*4", - 470: "-11*4+514", + 470: "(-11*4+514)", 466: "11+451+4", 460: "114*(5-1)+4", 458: "11+451-4", 457: "1+1+451+4", 456: "1*1+451+4", 455: "1-1+451+4", - 454: "-1+1*451+4", - 453: "-1-1+451+4", + 454: "(-1+1*451+4)", + 453: "(-1-1+451+4)", 452: "114*(5-1)-4", 450: "(1+1)*45*(1+4)", 449: "1+1+451-4", 448: "1+1*451-4", 447: "1/1*451-4", - 446: "1*-1+451-4", - 445: "-1-1+451-4", - 444: "-11+451+4", + 446: "1*(-1)+451-4", + 445: "(-1-1+451-4)", + 444: "(-11+451+4)", 440: "(1+1)*4*(51+4)", - 438: "(1+145)*-(1-4)", - 436: "-11+451-4", - 435: "-1*145*(1-4)", - 434: "-1-145*(1-4)", + 438: "(1+145)*(-(1-4))", + 436: "(-11+451-4)", + 435: "(-1*145*(1-4))", + 434: "(-1-145*(1-4))", 432: "(1-145)*(1-4)", 412: "(1+1)*4*51+4", 404: "(1+1)*4*51-4", - 400: "-114+514", - 396: "11*4*-(5-14)", + 400: "(-114+514)", + 396: "11*4*(-(5-14))", 385: "(11-4)*(51+4)", 376: "(1+1)*4*(51-4)", 375: "(1+14)*5*(1+4)", @@ -318,45 +318,45 @@ const homo = ((Nums) => { 363: "(1+1451)/4", 361: "(11-4)*51+4", 360: "(1+1)*45*1*4", - 357: "(114+5)*-(1-4)", + 357: "(114+5)*(-(1-4))", 353: "(11-4)*51-4", 352: "(1+1)*(45-1)*4", - 351: "1+14*-5*-(1+4)", + 351: "1+14*(-5)*(-(1+4))", 350: "1*(1+4)*5*14", - 349: "-1+14*5*(1+4)", + 349: "(-1+14*5*(1+4))", 341: "11*(45-14)", - 337: "1-14*-(5+1)*4", + 337: "1-14*(-(5+1))*4", 336: "1*14*(5+1)*4", - 335: "-1+14*(5+1)*4", + 335: "(-1+14*(5+1)*4)", 329: "(11-4)*(51-4)", - 327: "-(114-5)*(1-4)", - 325: "-(1-14)*5*(1+4)", + 327: "(-(114-5)*(1-4))", + 325: "(-(1-14)*5*(1+4))", 318: "114+51*4", - 312: "(1-14)*-(5+1)*4", + 312: "(1-14)*(-(5+1))*4", 300: "(11+4)*5/1*4", - 297: "-11*(4+5)*(1-4)", + 297: "(-11*(4+5)*(1-4))", 291: "11+4*5*14", 286: "(1145-1)/4", 285: "(11+4)*(5+14)", 282: "1+1+4*5*14", 281: "1+14*5/1*4", 280: "1-1+4*5*14", - 279: "1*-1+4*5*14", - 278: "-1-1+4*5*14", + 279: "1*(-1)+4*5*14", + 278: "(-1-1+4*5*14)", 275: "1*(1+4)*(51+4)", - 270: "(1+1)*45*-(1-4)", - 269: "-11+4*5*14", + 270: "(1+1)*45*(-(1-4))", + 269: "(-11+4*5*14)", 268: "11*4*(5+1)+4", 267: "1+14*(5+14)", 266: "1*14*(5+14)", - 265: "-1+14*(5+14)", + 265: "(-1+14*(5+14))", 260: "1*(14+51)*4", 259: "1*(1+4)*51+4", 257: "(1+1)/4*514", 252: "(114-51)*4", - 251: "1*-(1+4)*-51-4", + 251: "1*(-(1+4))*(-51)-4", 248: "11*4+51*4", - 247: "-(1-14)*(5+14)", + 247: "(-(1-14)*(5+14))", 240: "(11+4)*(5-1)*4", 236: "11+45*(1+4)", 235: "1*(1+4)*(51-4)", @@ -377,85 +377,85 @@ const homo = ((Nums) => { 217: "11*4*5+1-4", 216: "11*4*5-1*4", 215: "11*4*5-1-4", - 214: "-11+45*(1+4)", + 214: "(-11+45*(1+4))", 212: "(1+1)*4+51*4", 211: "11-4+51*4", 210: "1+1+4+51*4", 209: "1+1*4*51+4", 208: "1*1*4+51*4", - 207: "-1+1*4*51+4", + 207: "(-1+1*4*51+4)", 206: "11*4*5-14", 204: "(1-1)/4+51*4", 202: "1+1-4+51*4", 201: "1/1-4+51*4", 200: "1/1*4*51-4", - 199: "1*-1+4*51-4", - 198: "-1-1+4*51-4", - 197: "-11+4+51*4", - 196: "-(1+1)*4+51*4", + 199: "1*(-1)+4*51-4", + 198: "(-1-1+4*51-4)", + 197: "(-11+4+51*4)", + 196: "(-(1+1)*4+51*4)", 195: "(1-14)*5*(1-4)", 192: "(1+1)*4*(5+1)*4", 191: "1-14+51*4", - 190: "1*-14+51*4", - 189: "-11-4+51*4", + 190: "1*(-14)+51*4", + 189: "(-11-4+51*4)", 188: "1-1-(4-51)*4", 187: "1/-1+4*(51-4)", 186: "1+1+(45+1)*4", - 185: "1-1*-(45+1)*4", + 185: "1-1*(-(45+1))*4", 184: "114+5*14", - 183: "-1+1*(45+1)*4", + 183: "(-1+1*(45+1)*4)", 182: "1+1+45/1*4", 181: "1+1*45*1*4", 180: "1*1*45*1*4", - 179: "-1/1+45*1*4", - 178: "-1-1+45*1*4", + 179: "(-1/1+45*1*4)", + 178: "(-1-1+45*1*4)", 177: "1+1*(45-1)*4", 176: "1*1*(45-1)*4", - 175: "-1+1*(45-1)*4", - 174: "-1-1+(45-1)*4", + 175: "(-1+1*(45-1)*4)", + 174: "(-1-1+(45-1)*4)", 172: "11*4*(5-1)-4", 171: "114*(5+1)/4", - 170: "(11-45)*-(1+4)", + 170: "(11-45)*(-(1+4))", 169: "114+51+4", - 168: "(11+45)*-(1-4)", - 165: "11*-45/(1-4)", + 168: "(11+45)*(-(1-4))", + 165: "11*(-45)/(1-4)", 161: "114+51-4", 160: "1+145+14", 159: "1*145+14", - 158: "-1+145+14", - 157: "1*(1-4)*-51+4", - 154: "11*(4-5)*-14", + 158: "(-1+145+14)", + 157: "1*(1-4)*(-51)+4", + 154: "11*(4-5)*(-14)", 152: "(1+1)*4*(5+14)", 151: "1+145+1+4", 150: "1+145*1+4", 149: "1*145*1+4", 148: "1*145-1+4", - 147: "-1+145-1+4", - 146: "11+45*-(1-4)", + 147: "(-1+145-1+4)", + 146: "11+45*(-(1-4))", 143: "1+145+1-4", 142: "1+145*1-4", 141: "1+145-1-4", 140: "1*145-1-4", - 139: "-1+145-1-4", - 138: "-1*(1+45)*(1-4)", + 139: "(-1+145-1-4)", + 138: "(-1*(1+45)*(1-4))", 137: "1+1-45*(1-4)", 136: "1*1-45*(1-4)", - 135: "-1/1*45*(1-4)", + 135: "(-1/1*45*(1-4))", 134: "114+5/1*4", 133: "114+5+14", 132: "1+145-14", 131: "1*145-14", - 130: "-1+145-14", - 129: "114+5*-(1-4)", + 130: "(-1+145-14)", + 129: "114+5*(-(1-4))", 128: "1+1+(4+5)*14", 127: "1-14*(5-14)", 126: "1*(14-5)*14", - 125: "-1-14*(5-14)", + 125: "(-1-14*(5-14))", 124: "114+5+1+4", 123: "114-5+14", 122: "114+5-1+4", 121: "11*(45-1)/4", - 120: "-(1+1)*4*5*(1-4)", + 120: "(-(1+1)*4*5*(1-4))", 118: "(1+1)*(45+14)", 117: "(1-14)*(5-14)", 116: "114+5+1-4", @@ -464,8 +464,8 @@ const homo = ((Nums) => { 113: "114-5/1+4", 112: "114-5-1+4", 111: "11+4*5*(1+4)", - 110: "-(11-451)/4", - 107: "11-4*-(5+1)*4", + 110: "(-(11-451)/4)", + 107: "11-4*(-(5+1))*4", 106: "114-5+1-4", 105: "114+5-14", 104: "114-5-1-4", @@ -482,25 +482,25 @@ const homo = ((Nums) => { 93: "(1+1)*45-1+4", 92: "(1+1)*(45-1)+4", 91: "11*4+51-4", - 90: "-114+51*4", + 90: "(-114+51*4)", 89: "(1+14)*5+14", 88: "1*14*(5+1)+4", 87: "11+4*(5+14)", 86: "(1+1)*45*1-4", 85: "1+14+5*14", 84: "1*14+5*14", - 83: "-1+14+5*14", + 83: "(-1+14+5*14)", 82: "1+1+4*5/1*4", 81: "1/1+4*5*1*4", 80: "1-1+4*5*1*4", - 79: "1*-1+4*5/1*4", + 79: "1*(-1)+4*5/1*4", 78: "(1+1)*4+5*14", 77: "11-4+5*14", 76: "1+1+4+5*14", 75: "1+14*5*1+4", 74: "1/1*4+5*14", 73: "1*14*5-1+4", - 72: "-1-1+4+5*14", + 72: "(-1-1+4+5*14)", 71: "(1+14)*5-1*4", 70: "11+45+14", 69: "1*14+51+4", @@ -514,17 +514,17 @@ const homo = ((Nums) => { 61: "1+1+45+14", 60: "11+45*1+4", 59: "114-51-4", - 58: "-1+1*45+14", + 58: "(-1+1*45+14)", 57: "1+14*5-14", 56: "1*14*5-14", - 55: "-1+14*5-14", + 55: "(-1+14*5-14)", 54: "11-4+51-4", 53: "11+45+1-4", 52: "11+45/1-4", 51: "11+45-1-4", 50: "1+1*45/1+4", 49: "1*1*45/1+4", - 48: "-11+45+14", + 48: "(-11+45+14)", 47: "1/-1+45-1+4", 46: "11*4+5+1-4", 45: "11+4*5+14", @@ -532,18 +532,18 @@ const homo = ((Nums) => { 43: "1+1*45+1-4", 42: "11+45-14", 41: "1/1*45*1-4", - 40: "-11+4*51/4", - 39: "-11+45+1+4", - 38: "-11+45*1+4", - 37: "-11+45-1+4", + 40: "(-11+4*51/4)", + 39: "(-11+45+1+4)", + 38: "(-11+45*1+4)", + 37: "(-11+45-1+4)", 36: "11+4*5+1+4", 35: "11*4+5-14", 34: "1-14+51-4", 33: "1+1+45-14", 32: "1*1+45-14", 31: "1/1*45-14", - 30: "1*-1+45-14", - 29: "-11+45-1-4", + 30: "1*(-1)+45-14", + 29: "(-11+45-1-4)", 28: "11+4*5+1-4", 27: "11+4*5/1-4", 26: "11-4+5+14", @@ -551,8 +551,8 @@ const homo = ((Nums) => { 24: "1+14-5+14", 23: "1*14-5+14", 22: "1*14+5-1+4", - 21: "-1-1+4+5+14", - 20: "-11+45-14", + 21: "(-1-1+4+5+14)", + 20: "(-11+45-14)", 19: "1+1+4*5+1-4", 18: "1+1+4*5*1-4", 17: "11+4*5-14", @@ -560,17 +560,17 @@ const homo = ((Nums) => { 15: "1+14-5+1+4", 14: "11+4-5/1+4", 13: "1*14-5/1+4", - 12: "-11+4+5+14", - 11: "11*-4+51+4", - 10: "-11/4+51/4", + 12: "(-11+4+5+14)", + 11: "11*(-4)+51+4", + 10: "(-11/4+51/4)", 9: "11-4+5+1-4", 8: "11-4+5/1-4", 7: "11-4+5-1-4", 6: "1-14+5+14", 5: "11-4*5+14", - 4: "-11-4+5+14", - 3: "11*-4+51-4", - 2: "-11+4-5+14", + 4: "(-11-4+5+14)", + 3: "11*(-4)+51-4", + 2: "(-11+4-5+14)", 1: "11/(45-1)*4", 0: "(1-1)*4514", "⑨": "11-4-5+1-4", From 576ac6d7a2f4eadee5cfcb8e59a9e2179ae95397 Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Wed, 7 Sep 2022 17:16:57 +0800 Subject: [PATCH 5/5] add checker --- homo.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/homo.js b/homo.js index 43ff35f..5802c13 100644 --- a/homo.js +++ b/homo.js @@ -7,11 +7,8 @@ const homo = ((Nums) => { } const isDotRegex = /\.(\d+?)0{0,}$/ const demolish = (num) => { - if (typeof num !== "number") - return "" - - if (num === Infinity || Number.isNaN(num)) - return `这么恶臭的${num}有必要论证吗` + if (typeof num !== "number" || num === Infinity || Number.isNaN(num)) + return 114514 if (num < 0) return `(⑨)*(${demolish(num * -1)})`.replace(/\*\(1\)/g, "") @@ -51,7 +48,19 @@ const homo = ((Nums) => { expr = expr.replace(/\*\*/g, "^") return expr } - return (num) => finisher(demolish(num)) + //Check if the result of the string returned by finisher(demolish(num)) is num + const checker = (expr,num) => { + if (typeof num !== "number") + return "林檎!林檎!" + if (num === Infinity || Number.isNaN(num)) + return `这么恶臭的${num}有必要论证吗` + const res = eval(expr) + if (res === num) + return expr + else + return "论证失败(悲)" + } + return (num) => checker(finisher(demolish(num)),num) })({ 229028: "(114514+114514)", 114514: "114514",