ES6 জাভাস্ক্রিপ্ট 2126 + 311 = 2437 স্কোর
m=Math;s=n=>[b=m.min(m.sqrt(n)+.5|0,15),n-b*b];f=n=>(n<0?'d':'i').repeat(m.abs(n));g=(n,t)=>n<4?f(n):g((t=s(n))[0])+'s'+f(t[1]);q=n=>((x=g(n)).length>(z=[...n+''].map((k,i,a)=>i?(a[i-1]==a[i]?'':(y=f((l=s(k))[0]-a[i-1])+(l[0]?'s':'')+f(l[1])).length>m.abs(Q=a[i]-a[i-1])?f(Q):y):g(k)).join('o')).length?z:x)+'o'
সেমি-মন্তব্য করেছেন:
m = Math; // Keep a reference to math
// This function returns the closest perfect square and the distance from that square to the number
// E.g. s(10) --> [3, 1] because 3^2 + 1 = 10
s = n => [b = m.min(m.sqrt(n) + .5 | 0, 15), n - b * b];
// This creates a bunch of "d"s or "i"s
// E.g. f(3) --> "iii" or f(-2) --> "dd"
f = n => Array(m.abs(n) + 1).join(n < 0 ? 'd' : 'i');
// This constructs the number as a number rather than by digit
g = (n, t) => n < 4 ?
// If n is less than 4, then we can just increment in normally (base case)
f(n) :
// Otherwise, build the square root recursively and shift
g((t = s(n))[0]) + 's' + f(t[1]);
// This maps based on digits (constructs the number by digit)
// This has now been removed and replaced inline because it is only used once
d = n => (a = [...(n + '')]).map((k, i) => i ? (a[i - 1] == a[i] ? '' : f((l = s(k))[0] - a[i - 1]) + (l[0] ? 's' : '') + f(l[1])) : g(k)).join('o');
// For the official function, compare the digit-method and nondigit-method and return the best one
q = n => ((x = g(n)).length > (z = d(n)).length ? z : x) + 'o'
এটি ডেডফিশে, আপনি একাধিক অক্ষর মুদ্রণ করতে পারবেন এই সুবিধাটি গ্রহণ করে।
উদাহরণ: 10
সংকলন iodo
যা "এক মুদ্রণ হ্রাস, মুদ্রণ শূন্য।"
ব্যবহার:
q(10) // --> iodo
q(16) // --> iisso
আউটপুটটির জেসন ডেটা এখানে:
{
"0": "o",
"1": "io",
"2": "iio",
"3": "iiio",
"4": "iiso",
"5": "iisio",
"6": "iisiio",
"7": "iiisddo",
"8": "iiisdo",
"9": "iiiso",
"10": "iodo",
"11": "ioo",
"12": "ioio",
"13": "ioiio",
"14": "ioiso",
"15": "iissdo",
"16": "iisso",
"17": "iissio",
"18": "iissiio",
"19": "ioiiso",
"20": "iioddo",
"21": "iiodo",
"22": "iioo",
"23": "iioio",
"24": "iioso",
"25": "iisiso",
"26": "iisisio",
"27": "iisisiio",
"28": "iioisdo",
"29": "iioiso",
"30": "iiiodddo",
"31": "iiioddo",
"32": "iiiodo",
"33": "iiioo",
"34": "iiioio",
"35": "iiioiio",
"36": "iisiiso",
"37": "iisiisio",
"38": "iiiosdo",
"39": "iiioso",
"40": "iisoddddo",
"41": "iisodddo",
"42": "iisoddo",
"43": "iisodo",
"44": "iisoo",
"45": "iisoio",
"46": "iisoiio",
"47": "iisoiiio",
"48": "iisodsdo",
"49": "iisodso",
"50": "iiisddsio",
"51": "iiisddsiio",
"52": "iisiodddo",
"53": "iisioddo",
"54": "iisiodo",
"55": "iisioo",
"56": "iisioio",
"57": "iisioiio",
"58": "iisioiiio",
"59": "iisioddso",
"60": "iiisdsddddo",
"61": "iiisdsdddo",
"62": "iiisdsddo",
"63": "iiisdsdo",
"64": "iiisdso",
"65": "iiisdsio",
"66": "iisiioo",
"67": "iisiioio",
"68": "iisiioiio",
"69": "iisiioiiio",
"70": "iiisdsiiiiiio",
"71": "iiisdsiiiiiiio",
"72": "iiisddodddddo",
"73": "iiisddoddddo",
"74": "iiisddodddo",
"75": "iiisddoddo",
"76": "iiisddodo",
"77": "iiisddoo",
"78": "iiissdddo",
"79": "iiissddo",
"80": "iiissdo",
"81": "iiisso",
"82": "iiissio",
"83": "iiissiio",
"84": "iiissiiio",
"85": "iiissiiiio",
"86": "iiisdoddo",
"87": "iiisdodo",
"88": "iiisdoo",
"89": "iiisdoio",
"90": "iiissiiiiiiiiio",
"91": "iiisoddddddddo",
"92": "iiisodddddddo",
"93": "iiisoddddddo",
"94": "iiisodddddo",
"95": "iiisoddddo",
"96": "iiisodddo",
"97": "iiisoddo",
"98": "iiisodo",
"99": "iiisoo",
"100": "iodoo",
"101": "iodoio",
"102": "iodoiio",
"103": "iodoiiio",
"104": "iodoiiso",
"105": "iodoiisio",
"106": "iodoiisiio",
"107": "iodoiiisddo",
"108": "iodoiiisdo",
"109": "iodoiiiso",
"110": "ioodo",
"111": "iooo",
"112": "iooio",
"113": "iooiio",
"114": "iooiso",
"115": "iooisio",
"116": "iooisiio",
"117": "iooiisddo",
"118": "iooiisdo",
"119": "iooiiso",
"120": "ioioddo",
"121": "ioiodo",
"122": "ioioo",
"123": "ioioio",
"124": "ioioso",
"125": "ioiosio",
"126": "ioiosiio",
"127": "ioioisddo",
"128": "ioioisdo",
"129": "ioioiso",
"130": "ioiiodddo",
"131": "ioiioddo",
"132": "ioiiodo",
"133": "ioiioo",
"134": "ioiioio",
"135": "ioiioiio",
"136": "ioiioiiio",
"137": "ioiiosddo",
"138": "ioiiosdo",
"139": "ioiioso",
"140": "ioisoddddo",
"141": "ioisodddo",
"142": "ioisoddo",
"143": "ioisodo",
"144": "ioisoo",
"145": "ioisoio",
"146": "ioisoiio",
"147": "ioisoiiio",
"148": "ioisodsdo",
"149": "ioisodso",
"150": "ioisiodddddo",
"151": "ioisioddddo",
"152": "ioisiodddo",
"153": "ioisioddo",
"154": "ioisiodo",
"155": "ioisioo",
"156": "ioisioio",
"157": "ioisioiio",
"158": "ioisioiiio",
"159": "ioisioddso",
"160": "ioisiioddddddo",
"161": "ioisiiodddddo",
"162": "ioisiioddddo",
"163": "ioisiiodddo",
"164": "ioisiioddo",
"165": "ioisiiodo",
"166": "ioisiioo",
"167": "ioisiioio",
"168": "iissdddsdo",
"169": "iissdddso",
"170": "iissdddsio",
"171": "iissdddsiio",
"172": "iissdddsiiio",
"173": "iissdddsiiiio",
"174": "ioiisddodddo",
"175": "ioiisddoddo",
"176": "ioiisddodo",
"177": "ioiisddoo",
"178": "ioiisddoio",
"179": "ioiisddoiio",
"180": "ioiisdoddddddddo",
"181": "ioiisdodddddddo",
"182": "ioiisdoddddddo",
"183": "ioiisdodddddo",
"184": "ioiisdoddddo",
"185": "ioiisdodddo",
"186": "ioiisdoddo",
"187": "ioiisdodo",
"188": "ioiisdoo",
"189": "ioiisdoio",
"190": "iissddsddddddo",
"191": "iissddsdddddo",
"192": "iissddsddddo",
"193": "iissddsdddo",
"194": "iissddsddo",
"195": "iissddsdo",
"196": "iissddso",
"197": "iissddsio",
"198": "ioiisodo",
"199": "ioiisoo",
"200": "iioddoo",
"201": "iioddoio",
"202": "iioddoiio",
"203": "iioddoiiio",
"204": "iioddoiiso",
"205": "iioddoiisio",
"206": "iioddoiisiio",
"207": "iioddoiiisddo",
"208": "iioddoiiisdo",
"209": "iioddoiiiso",
"210": "iiododo",
"211": "iiodoo",
"212": "iiodoio",
"213": "iiodoiio",
"214": "iiodoiso",
"215": "iiodoisio",
"216": "iiodoisiio",
"217": "iiodoiisddo",
"218": "iiodoiisdo",
"219": "iiodoiiso",
"220": "iiooddo",
"221": "iioodo",
"222": "iiooo",
"223": "iiooio",
"224": "iiooso",
"225": "iissdso",
"226": "iissdsio",
"227": "iissdsiio",
"228": "iiooisdo",
"229": "iiooiso",
"230": "iioiodddo",
"231": "iioioddo",
"232": "iioiodo",
"233": "iioioo",
"234": "iioioio",
"235": "iioioiio",
"236": "iioioiiio",
"237": "iioiosddo",
"238": "iioiosdo",
"239": "iioioso",
"240": "iiosoddddo",
"241": "iiosodddo",
"242": "iiosoddo",
"243": "iiosodo",
"244": "iiosoo",
"245": "iiosoio",
"246": "iiosoiio",
"247": "iiosoiiio",
"248": "iiosodsdo",
"249": "iiosodso",
"250": "iiosiodddddo",
"251": "iiosioddddo",
"252": "iiosiodddo",
"253": "iiosioddo",
"254": "iiosiodo",
"255": "iiosioo"
}
এটি এই কোড দ্বারা উত্পন্ন হয়েছিল:
var c = {}, result = 0;
for (var i = 0; i <= 255; ++i) result += (c[i] = q(i)).length;
যা প্রিন্ট করে result = (the result)
এবং c =
উপরের জিনিসটি।
এটি বেশ সহজ হওয়া সত্ত্বেও একটি উল্লেখযোগ্য উচ্চ স্কোর পায়। এটি নিকটতম নিখুঁত বর্গক্ষেত্র অনুসন্ধান করে, সেই নিখুঁত বর্গক্ষেত্রের বর্গমূল গণনা করে, 'গুলি' যুক্ত করে এবং যথাযথভাবে বৃদ্ধি / হ্রাস।
পুরানো সংস্করণ যা "10" = "একটি মুদ্রণ করুন, শূন্য প্রিন্ট করুন" এই সত্যটি ব্যবহার করেন নি
m=Math;s=n=>[b=m.sqrt(n)+.5|0,n-b*b];f=(n)=>Array(m.abs(n)+1).join('id'[+(n<0)]);g=(n,t)=>n<4?f(n):g((t=s(n))[0])+'s'+f(t[1]);q=n=>g(n)+'o'