दरअसल इंटेगर मेटागॉल्फ


17

पृष्ठभूमि

वास्तव में ( गंभीर रूप से उत्तराधिकारी ) एक स्टैग-आधारित अनिवार्यता वाली गोल्फ गोल्फिंग भाषा है, जिसे मैंने 2015 के नवंबर में बनाया था। कई अन्य गोल्फिंग भाषाओं की तरह, इसमें एक-एक बाइट कमांड होती है, जो स्टैक की सामग्री के आधार पर विभिन्न कार्य करती है। इसकी एक विशेषता गणित है - इसमें गणित आधारित आज्ञाओं की एक विस्तृत विविधता है। हालांकि, गणित संचालन करने के लिए, आपको स्टैक पर (एक या अधिक) नंबर डालने होंगे। संभव के रूप में कुछ बाइट्स में एक विशिष्ट मूल्य धक्का मुश्किल है, क्योंकि कई अलग-अलग विकल्प हैं। इस चुनौती में, आप वास्तव में ऐसा कर रहे होंगे: संख्याओं (विशेष रूप से पूर्णांकों) का प्रतिनिधित्व करते हुए वास्तव में संभव के रूप में कुछ बाइट्स में।

चुनौती

Nइनपुट के रूप में एक पूर्णांक को देखते हुए , आउटपुट मान्य वास्तव में कोड है जिसके परिणामस्वरूप Nस्टैक को धकेल दिया जाता है।

  • इनपुट एक 32-बिट हस्ताक्षरित दो के पूरक पूर्णांक (यानी समावेशी सीमा में पूर्णांक [-2147483648, 2147483647]) की सीमा के भीतर होगा ।
  • परिणाम एक पूर्णांक होना चाहिए (फ्लोट, स्ट्रिंग, सूची या फ़ंक्शन नहीं), और स्टैक के शीर्ष पर होना चाहिए।
  • आप स्टैक की सामग्री के बारे में कोई धारणा नहीं बना सकते हैं (जैसे कि यह खाली है या नहीं)। स्टैक पर किसी भी मौजूदा मान को संशोधित या पुनर्व्यवस्थित नहीं किया जाना चाहिए।
  • वास्तव में, जिस समय मैं यह चुनौती लिख रहा हूं, उस समय का नवीनतम कमिटमेंट उपयोग किया जाना है। यदि मैं बग फिक्स या प्रदर्शन एन्हांसमेंट्स (या किसी अन्य मामूली परिवर्तन जो अनुमत कमांड की कार्यक्षमता को हटा या परिवर्तित नहीं करता है) बनाते हैं, तो मैं इस संस्करण को अपडेट करूंगा।
  • आपका समाधान कम से कम और साथ ही तुच्छ समाधान ( :एक संख्यात्मक शाब्दिक बनाने के लिए इनपुट के लिए प्रस्तुत करना) करना चाहिए।
  • आपका स्कोर तुच्छ समाधानों की लंबाई का योग होगा, स्कोरिंग के लिए उपयोग किए गए 1000-बिट हस्ताक्षरित दो के पूरक पूर्णांक के चयन के लिए आउटपुट की लंबाई का योग माइनस है, जो नीचे पाया जा सकता है। मैं किसी भी समय स्कोरिंग पूर्णांकों को बदलने का अधिकार सुरक्षित रखता हूं, अगर कोई आवश्यकता है (जैसे कि परीक्षण मामलों के लिए अनुकूलन या परीक्षण के मामले पूरी तरह से पर्याप्त नहीं हैं)।
  • समाधान प्रत्येक इनपुट के लिए 30 सेकंड के भीतर एक वैध जवाब का उत्पादन करना चाहिए। टाइमिंग एक मानक मुक्त Cloud9 कार्यक्षेत्र पर किया जाएगा ।

आदेश

सादगी के लिए, केवल 141 में से (वर्तमान में) 208 आदेशों का उपयोग किया जा सकता है, और उन 141 के कई अधिभार जो संख्या-क्रंचिंग से असंबंधित हैं, हटा दिए गए हैं। यहां अनुमत कमांड की सूची है (प्रारूप है <hex code> (<symbol>): <descriptions of functions based on stack values and types>:

0B (♂): take the next command and map it over the top of the stack (for example, ♂A is equivalent to `A`M)
1F (▼): pop a,b: push b//gcd(a,b),a//gcd(a,b); pop [a]: push [x//gcd([a]) for x in [a]]
20 ( ): push the # of elements on the stack (push len(stack))
21 (!): pop a: push a! (factorial(a))
22 ("): string literal, reads until next " and pushes value onto stack. An implied " is present at EOF if needed.
23 (#): pop a: push list(a)
25 (%): pop a,b: push a%b
26 (&): pop a,b: push a & b (bitwise AND)
27 ('): pushes next character onto stack as character literal (length-1 string)
28 ((): rotates stack right by 1
29 ()): rotates stack left by 1
2A (*): pop a,b: push a*b; pop a,[b] or [b],a: apply a* to each element in the array; pop [a],[b]: push dot product of [a] and [b] (sum([a[i]*b[i] for i in len(a)])) (shorter is padded with 0s)
2B (+): pop a,b: push a+b; pop [a],[b]: push [a][b] (append [b] to [a]); pop a,[b] or [b],a: apply a+ to each element in the array
2D (-): pop a,b: push a-b; pop [a],[b]: push [a]-[b] (all elements of [a] not in [b])
2F (/): pop a,b: push a/b (float division); pop [a]: rotate [a] right by 1, push [a]
30 (0): push 0
31 (1): push 1
32 (2): push 2
33 (3): push 3
34 (4): push 4
35 (5): push 5
36 (6): push 6
37 (7): push 7
38 (8): push 8
39 (9): push 9
3A (:): numeric literal delimiter: pushes the longest string of characters in '0123456789+-.ij' as a numeric
3B (;): pop a: push a,a (duplicates top element)
3C (<): pop a,b: push 1 if a<b else 0
3D (=): pop a,b: push 1 if a==b else 0
3E (>): pop a,b: push 1 if a>b else 0
40 (@): pop a,b: push a,b (rotate top 2 elements)
41 (A): pop a: push abs(a)
43 (C): pop a: push cos(a)
44 (D): pop a: push a-1; pop [a]: push stddev([a])
45 (E): pop a: push erf(a); pop [a],b: push [a][b] (bth item in [a])
46 (F): pop a: push Fib(a) (Fib(0)=0, Fib(1)=Fib(2)=1); pop [a]: push a[0]
48 (H): pop [a],b: push [a][:b]
49 (I): pop a,b,c: push b if a is truthy, else push c
4B (K): pop a: push ceil(a)
4C (L): pop a: push floor(a)
4D (M): pop f,[a], execute f for each element in [a], using the element as a temporary stack, push [a] (similar to map(f,[a])); pop [a]: push max([a])
4E (N): pop [a]: push a[-1]
50 (P): pop a: push the a-th prime (zero-indexed)
52 (R): pop f,[a]: call f, using [a] as a temporary stack, push [a] (similar to reduce(f,[a])); pop [a]: push [a][::-1] (reverse); pop a: push [1,2,...,a] (range(1,a+1))
53 (S): pop a: push sin(a); pop [a]: push sorted(a)
54 (T): pop a: push tan(a); pop [a],b,c: set [a][b] to c, push [a]
55 (U): pop [a],[b]: push union of [a] and [b]
57 (W): loop delimiter: peek top of stack, repeat code in loop while a evaluates to true
58 (X): pop a: discard
59 (Y): pop a: push !bool(a) (logical negate, opposite of b)
5A (Z): pop [a],[b]: push zip([a],[b]); pop a, zip the next a lists
5B ([): begin list literal, values are delimited by commas (,)
5C (\): pop a,b: push a/b (integer division); pop [a]: rotate [a] left by 1, push [a]
5D (]): end list literal
5E (^): pop a,b: push a XOR b
5F (_): pop a: push ln(a)
60 (`): function literal delimiter, pushes function whose body contains all of the commands until the next `. An implied ` is present at EOF if needed.
61 (a): invert the stack ([a,b,c,d] -> [d,c,b,a])
62 (b): pop a: push 0 if a==0 else 1; pop "a" or [a]: push 0 if len(a)==0 else 1; pop f: push 0 if len(f)==0 else 1
63 (c): pop a: push character at ordinal a%256; pop [a],b: push [a].count(b)
64 (d): pop [a]: dequeue b from [a], push [a],b
65 (e): pop a: push exp(a)
66 (f): pop a: push the Fibonacci index of a if a is a Fibonacci number, else -1
67 (g): pop a,b: push gcd(a,b); pop [a]: push gcd([a])
68 (h): pop a,b: push sqrt(a*a+b*b) (Euclidean norm)
69 (i): pop [a]: push each element from [a], starting from end (flatten)
6B (k): pop all elements from stack, convert to list (in the order they were on the stack, starting from the top), and push
6C (l): pop [a]: push len([a])
6D (m): pop a: push int(a),frac(a) (modf(a)); pop [a]: push min([a])
6E (n): pop a,b: push a b times
6F (o): pop [a],b: push b to [a], push [a]
70 (p): pop a: push 1 if a is prime else 0; pop [a]: pop b from [a], push [a],b
71 (q): pop [a],b: enqueue b in [a], push [a]
72 (r): pop a: push [0,1,...,a-1] (range(0,a))
75 (u): pop a: push a+1
77 (w): pop a: push the full positive prime factorization of |a| (18 -> [[2,1],[3,2]], -5 -> [[5,1]])
78 (x): pop a,b: push [a,b) (range(a,b)); pop [a]: push range(*a)
79 (y): pop a: push the positive prime factors of |a| (18 -> [2,3], -5 -> [5])
7B ({): pop a: rotate stack right a times
7C (|): pop a,b: push a | b (bitwise OR)
7D (}): pop a: rotate stack left a times
7E (~): pop a: push ~a (unary bitwise negate)
80 (Ç): pop a,b: push a+bi; pop [a]: pop pairs of real numerics b,c from [a] and push b+ci (appending 0 to [a] if len([a]) is odd)
83 (â): pop a: push asin(a)
84 (ä): pop a: push acos(a)
85 (à): pop a: push atan(a)
86 (å): pop a,b: push atan2(a,b)
87 (ç): pop a: push asinh(a)
88 (ê): pop a: push acosh(a)
89 (ë): pop a: push atanh(a)
8B (ï): push i, the imaginary unit (sqrt(-1) or 0+1i)
8C (î): pop a, push 0+ai; pop [a], push [a] with every element multiplied by i
8D (ì): pop a: push 1/a
8E (Ä): pop a: push sinh(a)
8F (Å): pop a: push cosh(a)
90 (É): pop a: push tanh(a)
91 (æ): pop [a]: push mean([a])
9A (Ü): pop [a]: push mode([a])
9B (¢): pop a,b: push abs(a)*sgn(b)
9D (¥): pop [a],[b]: push the result of pairwise addition of [a] and [b], padding the shorter with 0s
9E (₧): pop z: push phase(z)
A0 (á): pop z: push the complex conjugate of z
A1 (í): pop [a],b: push [a].index(b) (0-based, -1 if not found)
A7 (º): pop a: push degrees(a)
A8 (¿): pop a,b: push int(a,b) (interpret a as a base-b int)
A9 (⌐): pop a: push a+2
AA (¬): pop a: push a-2
AB (½): pop a: push a/2 (float division)
AC (¼): pop a: push a/4 (float division)
AD (¡): pop a,b: push a string representing a in base b
B0 (░): pop [a],[b]: push [[b][i] if [a][i] for i in len(b)], pads [a] with 0s if necessary
B1 (▒): pop a: push totient(a) (# of integers <= a that are coprime with a)
B2 (▓): pop a: push pi(a) (# of primes <= a)
B3 (│): duplicate stack ([a,b,c] => [a,b,c,a,b,c])
B4 (┤): pop a,b: push 1 if a and b are coprime else 0
B9 (╣): pop a: push the ath row in Pascal's triangle
C5 (┼): duplicate each element on stack ([a,b,c] => [a,a,b,b,c,c])
C6 (╞): pop a: make a total copies of each element on stack (3 [a,b,c] -> [a,a,a,b,b,b,c,c,c])
C7 (╟): pop a: pop a elements and push a list containing those elements in their original order
CB (╦): push pi
CC (╠): push e
D1 (╤): pop a: push 10**a
D2 (╥): pop a: push log(a) (log base 10)
D3 (╙): pop a: push 2**a
D4 (╘): pop a: push lg(a) (log base 2)
D5 (╒): push ln(2)
DB (█): pop a,b: push C(a,b) (aCb)
DC (▄): pop a,b: push P(a,b) (aPb)
E2 (Γ): pop a: push Gamma(a)
E3 (π): pop [a]: push product([a])
E4 (Σ): pop [a]: push sum([a])
E7 (τ): pop a: push 2*a
ED (φ): push phi (golden ratio)
F1 (±): pop a: push -a (unary negate)
F2 (≥): pop a,b: push a>=b
F3 (≤): pop a,b: push a<=b
F7 (≈): pop a: push int(a)
F8 (°): pop a: push radians(a)
FB (√): pop a: push sqrt(a)
FC (ⁿ): pop a,b: push pow(a,b)
FD (²): pop a: push a*a

[a] refers to an iterable (list, string, etc.), "a" refers to a string, f refers to a function, and a (and b, and c, and so on) refers to a numeric (or any data type, if the command is type-agnostic).

यह संभावना है कि इनमें से कई कमांड का उपयोग नहीं किया जाएगा, लेकिन मैंने उन्हें सिर्फ उसी स्थिति में शामिल किया है जब वे उपयोगी होते हैं।

स्कोरिंग

यहाँ पूर्णांक हैं जिनका उपयोग स्कोरिंग के लिए किया जाएगा:

-2124910654
-2117700574
-2098186988
-2095671996
-2083075613
-2058271687
-2052250777
-2024215903
-2019485642
-2016095616
-2009838326
-2009173317
-2007673992
-2000014444
-1999825668
-1992515610
-1989566707
-1975506037
-1955473208
-1950731112
-1949886423
-1920624450
-1918465596
-1916287469
-1905036556
-1903956118
-1888944417
-1865221863
-1856600057
-1842797147
-1835637734
-1812631357
-1805740096
-1798015647
-1726688233
-1723609647
-1713776890
-1700307138
-1687644479
-1645515069
-1617635994
-1610444000
-1579053372
-1556891649
-1549652116
-1537732956
-1535180388
-1527162056
-1524851611
-1524658412
-1523244369
-1521379172
-1520191198
-1519035741
-1516978241
-1508892332
-1489938422
-1482102944
-1481823232
-1470621147
-1469145091
-1446844485
-1441790509
-1437843276
-1435359182
-1434186947
-1429816311
-1429393781
-1419752032
-1400387846
-1385152926
-1372620863
-1369257355
-1361933674
-1360480816
-1334846204
-1323741718
-1323660173
-1312800992
-1308824840
-1304658551
-1287829999
-1283767920
-1276288210
-1264275838
-1263965596
-1262866901
-1255421887
-1251428680
-1244825786
-1243200329
-1235305532
-1233977691
-1220537074
-1214100716
-1199414474
-1190725823
-1190401800
-1178717689
-1172378149
-1147869245
-1142875190
-1138538768
-1137864183
-1124917489
-1102987222
-1095920186
-1083001017
-1080902655
-1047122002
-1031842676
-1029877334
-1020849489
-1001684838
-998419619
-990915088
-985235989
-982515261
-979074894
-974195629
-973832940
-965324937
-944246431
-938387588
-933873331
-932692878
-928039285
-927947459
-914008773
-907981688
-906376330
-903502449
-898112547
-887444438
-862658502
-843628573
-822463032
-786051095
-776932426
-776033951
-752042328
-746532472
-743149468
-740225710
-734414418
-725435852
-708101516
-699674783
-694869277
-693246525
-690571518
-689249770
-688581912
-686864294
-681445866
-647992869
-641101583
-631409299
-624686189
-613079884
-593711206
-591688546
-591331185
-574790069
-573024823
-565387051
-565137163
-556338668
-556291492
-541411509
-538932064
-500479857
-482419890
-468050561
-424532545
-420534171
-408741873
-406973874
-387664799
-382084509
-367095703
-352332569
-352195997
-346430007
-324596389
-320119776
-306594578
-305952425
-283718911
-267302378
-243302738
-242955859
-232180029
-225394407
-217418127
-212286453
-208344820
-191300139
-186177744
-175765723
-161763935
-157025501
-140389149
-132298608
-126175769
-70566352
-68748576
-53985905
-52674668
-50228620
-39678495
-19825663
-8349922
-8186722
-8125700
-8073135
-8043230
-7994382
-7874433
-7863624
-7784916
-7782477
-7696343
-7607278
-7531250
-7388060
-7368780
-7367625
-7353084
-7334489
-7281141
-7267149
-7140057
-7119066
-7010389
-6992089
-6975258
-6863360
-6784772
-6741079
-6585985
-6550401
-6520011
-6495144
-6459702
-6294273
-6178342
-6169344
-6139663
-6090928
-6022637
-5992707
-5971334
-5925304
-5880940
-5873707
-5807953
-5703992
-5692895
-5535131
-5488812
-5468330
-5404148
-5290247
-5274221
-5264144
-5234715
-5224048
-5179837
-5084014
-5043990
-5028537
-5011679
-4998333
-4922901
-4880159
-4874060
-4787390
-4749096
-4736217
-4502308
-4480611
-4424319
-4363262
-4349743
-4290050
-4240069
-4239657
-4174072
-4093051
-4045363
-4037689
-4033352
-3839265
-3766343
-3716899
-3680075
-3679053
-3581776
-3539227
-3461158
-3282526
-3205947
-3183427
-3169708
-3166430
-3089822
-3061531
-2947574
-2930733
-2919246
-2872882
-2830770
-2739228
-2713826
-2634018
-2613990
-2525529
-2439507
-2432921
-2376201
-2335005
-2307524
-2265548
-2176176
-2123133
-2108773
-2105934
-2075032
-2073940
-2045837
-2045648
-1978182
-1945769
-1935486
-1881608
-1654650
-1602520
-1506746
-1505294
-1475309
-1457605
-1327259
-1312217
-1178723
-1027439
-880781
-833776
-666675
-643098
-593446
-468772
-450369
-443225
-418164
-402004
-319964
-307400
-279414
-190199
-176644
-66862
-32745
-32686
-32352
-32261
-32035
-31928
-31414
-31308
-30925
-30411
-29503
-29182
-28573
-28500
-28093
-27743
-27716
-27351
-27201
-26834
-25946
-25019
-24469
-24341
-24292
-24151
-23732
-22769
-22242
-22002
-20863
-20762
-20644
-20189
-20009
-19142
-19036
-18980
-18616
-18196
-18123
-17942
-17915
-17601
-17494
-16669
-16417
-16317
-15051
-14796
-14742
-14600
-14443
-14159
-14046
-13860
-13804
-13745
-13634
-13498
-13497
-12688
-12471
-12222
-11993
-11467
-11332
-10783
-10250
-10114
-10089
-9930
-9434
-9336
-9128
-9109
-8508
-8460
-8198
-8045
-7850
-7342
-7229
-6762
-6302
-6245
-6171
-5957
-5842
-4906
-4904
-4630
-4613
-4567
-4427
-4091
-4084
-3756
-3665
-3367
-3186
-2922
-2372
-2331
-1936
-1683
-1350
-1002
-719
-152
-128
-127
-124
-122
-121
-119
-116
-113
-112
-111
-107
-104
-102
-101
-100
-95
-94
-91
-90
-87
-81
-80
-79
-78
-73
-72
-69
-68
-66
-65
-63
-57
-54
-52
-51
-48
-47
-46
-45
-43
-41
-37
-33
-31
-30
-27
-25
-21
-18
-15
-12
-8
-1
0
1
3
4
5
6
11
14
17
23
25
26
27
28
29
31
32
39
41
46
49
51
52
56
58
61
64
66
67
70
74
79
80
86
88
89
92
93
99
102
104
109
113
117
120
122
123
127
695
912
1792
2857
3150
3184
4060
4626
5671
6412
6827
7999
8017
8646
8798
9703
9837
10049
10442
10912
11400
11430
11436
11551
11937
12480
13258
13469
13689
13963
13982
14019
14152
14259
14346
15416
15613
15954
16241
16814
16844
17564
17702
17751
18537
18763
19890
21216
22238
22548
23243
23383
23386
23407
23940
24076
24796
24870
24898
24967
25139
25176
25699
26167
26536
26614
27008
27087
27142
27356
27458
27800
27827
27924
28595
29053
29229
29884
29900
30460
30556
30701
30815
30995
31613
31761
31772
32099
32308
32674
75627
80472
103073
110477
115718
172418
212268
242652
396135
442591
467087
496849
675960
759343
846297
881562
1003458
1153900
1156733
1164679
1208265
1318372
1363958
1411655
1522329
1559609
1677118
1693658
1703597
1811223
1831642
1838628
1884144
1931545
2085504
2168156
2170263
2239585
2308894
2329235
2364957
2432335
2435551
2596936
2684907
2691011
2705195
2738057
2851897
2925289
2995414
3051534
3216094
3267022
3271559
3338856
3440797
3638325
3651369
3718696
3724814
3811069
3854697
3866969
3893228
3963455
3984546
4098376
4100957
4128113
4200719
4256344
4286332
4306356
4316314
4438803
4458063
4461638
4552228
4563790
4584831
4607992
4884455
4907501
5045419
5066844
5150624
5157161
5190669
5314703
5337397
5434807
5440092
5502665
5523089
5547122
5566200
5582936
5634068
5690330
5776984
5778441
5818505
5826687
5827184
5885735
6010506
6084254
6131498
6138324
6250773
6292801
6306275
6315242
6331640
6484374
6502969
6545970
6666951
6690905
6763576
6766086
6895048
6912227
6929081
6941390
6978168
7045672
7085246
7193307
7197398
7270237
7276767
7295790
7375488
7472098
7687424
7840758
7880957
7904499
7948678
7974126
8015691
8037685
8112955
8131380
8140556
8142384
8220436
8308817
8331317
22581970
45809129
48103779
78212045
79674901
97299830
110308649
131744428
136663461
138485719
139842794
152061792
152685704
153070991
156228213
164884737
174776199
189346581
193148547
208582124
223891881
227308187
237373798
241214067
242476929
245495851
260606593
275202667
285717038
317009689
322759532
325369206
339724742
340122632
345010859
352375176
355826263
359695034
366118516
370008270
382712922
386379440
401153345
404986391
426084981
442843409
473909474
475192613
492302667
494747879
506279889
509813998
537558350
548423414
548467404
566383324
574188786
574792333
591678147
596558084
597423476
602432742
603067874
629552047
630893263
635249783
644959276
650710927
664859367
669433203
684329599
699991513
714451929
723556530
739294558
750895264
757618344
781123405
796973385
801637715
804776709
829003666
829219068
840167037
854882202
860066192
864304878
864808449
867107161
871871263
880591851
883020336
883178082
920223781
936008673
939417822
956776353
958281059
962183717
964059257
967860573
974322643
974999286
980009921
1032949015
1044249483
1064892676
1075628270
1080848022
1085571657
1173635593
1174809080
1176744978
1209783795
1212074975
1252323507
1254757790
1301450562
1302240953
1314501797
1315121266
1339304157
1364304289
1376260506
1383883477
1395158643
1411117754
1440755058
1448365702
1466814914
1468433821
1490105126
1493912601
1495600372
1509536621
1511014977
1545693948
1548924199
1566583103
1569747154
1574097219
1597784674
1610710480
1618324005
1646105187
1649417465
1655649169
1660619384
1668826887
1671093718
1672456990
1673477565
1678638502
1682302139
1682515769
1687920300
1690062315
1706031388
1713660819
1772170709
1778416812
1833443690
1861312062
1876004501
1876358085
1882435551
1916050713
1944906037
1950207172
1951593247
1973638546
1976288281
1994977271
2020053060
2025281195
2029716419
2033980539
2052482076
2058251762
2069273004
2073978021
2111013213
2119886932
2134609957
2140349794
2143934987

यहाँ एक पायथन 3 कार्यक्रम है जिसे सत्यापन को प्रस्तुत करने और स्कोर करने के लिए इस्तेमाल किया जा सकता है:

#!/usr/bin/env python3

import shlex
import os
import sys
import subprocess

try:
    from seriously import Seriously
except:
    print("Unable to load Seriously. Run 'pip3 install seriously' to install it.")
    exit()

if len(sys.argv) < 2:
    print("Usage: python3 {} 'command_to_call_your_program'".format(sys.argv[0]))
    exit()

sys.stdin = open(os.devnull, 'r')

with open('nums.txt') as f:
    nums = [int(x) for x in f]

total = 0

for num in nums:
    p = subprocess.Popen(shlex.split(sys.argv[1]), stdin=subprocess.PIPE, stdout=subprocess.PIPE, universal_newlines=True)
    try:
        out = p.communicate(str(num), timeout=30)[0].strip()
    except subprocess.TimeoutExpired:
        print("Program failed to finish within 30 seconds for {}".format(num))
        exit()
    val = Seriously().eval(out)[0]
    if not len(out) <= len(':'+str(num)):
        print("Failed to do at least as well as naive on {} ({})".format(num, out))
        exit()
    elif val != num or not isinstance(val, int):
        print("Incorrect output: {} instead of {}".format(val, num))
        exit()
    else:
        print("{}: {} ({})".format(num, out, len(out)))
        total += len(out)

print("Total:", total)

क्या हम लगातार डेटा का उपयोग कर सकते हैं? (जैसे प्रिम्स, या फाइबोनैचि संख्याओं का एक समूह संग्रहीत करने के लिए)
ब्लू

"आपका समाधान तुच्छ समाधान से बेहतर करना चाहिए, जब तक कि तुच्छ समाधान दिए गए मूल्य के लिए इष्टतम हो।" हर इनपुट के लिए? इसलिए यदि मेरा एल्गोरिथ्म केवल 99% समय के तुच्छ समाधान से बेहतर करता है, तो अन्य 1% मुझे अयोग्य घोषित करते हैं यदि उनमें से कोई भी इष्टतम नहीं है?
शुक्राणु

@Blue जो स्वीकार्य है।
मेगो

1
@ बेहतर इसका मतलब है कि यदि आप बेहतर समाधान है तो आप केवल तुच्छ समाधान का उत्पादन नहीं कर सकते।
मेगो

1
@ यह सामान्य है। भाषा का नाम सीरियसली है। इस चुनौती में, हम विशेष रूप से गंभीर रूप से v2 के साथ काम कर रहे हैं, जिसे वास्तव में नाम दिया गया है।
मेगो

जवाबों:


5

पायथन 3, 51 52 57 बाइट्स बचाए गए

यह कार्यक्रम ब्रूट 1-5 चरित्र कार्यक्रमों की एक महत्वपूर्ण संख्या के माध्यम से अपना रास्ता बनाता है, एक सीमित सेट का उपयोग करते हुए 54 56 निर्देश और प्रत्येक नए निर्देश को जोड़ने से पहले ढेर की स्थिति के आधार पर बहुत अधिक प्रूनिंग। मेरे लैपटॉप पर चलने में लगभग एक मिनट लगता है। 6 अक्षर घंटे लगेंगे।

#!/usr/bin/env python3
# -*- coding: cp437 -*-

import os
import sys
import json
import math
import time
import random
import timeit

try:
    from seriously import Seriously,chr_cp437,ord_cp437
except:
    print("Unable to load Seriously. Run 'pip3 install seriously' to install it.")
    exit()

MAXLEN=5
MAX=2**31


future_alphabet=[

    chr_cp437(0x4D), #  (M): pop f,[a], execute f for each element in [a], using the element as a temporary stack, push [a] (similar to map(f,[a])); pop [a]: push max([a])
    chr_cp437(0x52), #  (R): pop f,[a]: call f, using [a] as a temporary stack, push [a] (similar to reduce(f,[a])); pop [a]: push [a][::-1] (reverse); pop a: push [1,2,...,a] (range(1,a+1))
    chr_cp437(0x57), #  (W): loop delimiter: peek top of stack, repeat code in loop while a evaluates to true
    chr_cp437(0x60), #  (`): function literal delimiter, pushes function whose body contains all of the commands until the next `. An implied ` is present at EOF if needed.

]

def next_instruction(program,stack):
    plen = len(program)
    slen = len(stack)
    if plen>0 and program[-1]==chr_cp437(0x0B): # introspect the list on top of the stack
        maybes = set(next_instruction(program[:-1],[stack[0][0]]))
        # print(maybes)
        for i in stack[0][1:]:
            maybes = maybes & set(next_instruction(program[:-1],[i]))
            # print(maybes)
        maybes.discard(chr_cp437(0x72)) # no ranges of lists
        maybes.discard(chr_cp437(0xB9)) # no pascal rows of lists
        return list(maybes)

    candidates = []

    if plen==MAXLEN-1 and slen>1:
        if any(isinstance(x,list) for x in stack):
            return [] # lost cause
        if slen==2 and isinstance( stack[0], int ) and isinstance( stack[1], int ):
            candidates = candidates + [
                chr_cp437(0x2A), #  (*): pop a,b: push a*b; pop a,[b] or [b],a: apply a* to each element in the array; pop [a],[b]: push dot product of [a] and [b] (sum([a[i]*b[i] for i in len(a)])) (shorter is padded with 0s)
                chr_cp437(0x2B), #  (+): pop a,b: push a+b; pop [a],[b]: push [a][b] (append [b] to [a]); pop a,[b] or [b],a: apply a+ to each element in the array
                chr_cp437(0x2D), #  (-): pop a,b: push a-b; pop [a],[b]: push [a]-[b] (all elements of [a] not in [b])
                chr_cp437(0x2F), #  (/): pop a,b: push a/b (float division); pop [a]: rotate [a] right by 1, push [a]
                chr_cp437(0x5C), #  (\): pop a,b: push a/b (integer division); pop [a]: rotate [a] left by 1, push [a]
            ]
            if stack[0]>1 and stack[0]<int(math.pow(MAX,1.0/3))+1 and stack[1]>2 and stack[1]<int(math.log(MAX)/math.log(3))+1:
                candidates.append(chr_cp437(0xFC))  #  (ⁿ): pop a,b: push pow(a,b)
            if stack[0]>2 and stack[0]<1000 and stack[1]>2 and stack[1]<stack[0]:
                candidates = candidates + [
                    chr_cp437(0xDB), #  (█): pop a,b: push C(a,b) (aCb)
                    chr_cp437(0xDC) #  (▄): pop a,b: push P(a,b) (aPb)
                ]
        return candidates

    if plen==MAXLEN-1 and slen==1 and isinstance(stack[0],list):
        candidates = candidates + [
            chr_cp437(0xE3), #  (π): pop [a]: push product([a])
            chr_cp437(0xE4)  #  (Σ): pop [a]: push sum([a])
        ]
        return candidates

    candidates = candidates + [
        chr_cp437(0x30), #  (0): push 0
        chr_cp437(0x31), #  (1): push 1
        chr_cp437(0x32), #  (2): push 2
        chr_cp437(0x33), #  (3): push 3
        chr_cp437(0x34), #  (4): push 4
        chr_cp437(0x35), #  (5): push 5
        chr_cp437(0x36), #  (6): push 6
        chr_cp437(0x37), #  (7): push 7
        chr_cp437(0x38), #  (8): push 8
        chr_cp437(0x39)  #  (9): push 9
    ]

    if plen==0 or (plen>0 and program[-1]!=":"):
        candidates.append(chr_cp437(0x3A)) #  (:): numeric literal delimiter: pushes the longest string of characters in '0123456789+-.ij' as a numeric

    # if plen>0 and program[-1]==":":
    #     candidates.append(chr_cp437(0x2D)) # negative literal coming

    if slen>0:
        candidates.append(chr_cp437(0xB3)) #  (│): duplicate stack ([a,b,c] => [a,b,c,a,b,c])

    if slen>0 and isinstance( stack[0], int ):
        candidates = candidates + [
            chr_cp437(0x44), #  (D): pop a: push a-1; pop [a]: push stddev([a])
            chr_cp437(0x54), #  (T): pop a: push tan(a); pop [a],b,c: set [a][b] to c, push [a]
            chr_cp437(0x65), #  (e): pop a: push exp(a)
            chr_cp437(0x75), #  (u): pop a: push a+1
            chr_cp437(0xA9), #  (⌐): pop a: push a+2
            chr_cp437(0xAA), #  (¬): pop a: push a-2
            chr_cp437(0xAB), #  (½): pop a: push a/2 (float division)
            chr_cp437(0xAC), #  (¼): pop a: push a/4 (float division)
            chr_cp437(0xE7), #  (τ): pop a: push 2*a
            chr_cp437(0xF1), #  (±): pop a: push -a (unary negate)
            chr_cp437(0xFD), #  (²): pop a: push a*a
            chr_cp437(0x7E)  #  (~): pop a: push ~a (unary bitwise negate)
        ]
        candidates.append(chr_cp437(0x3B)) #  (;): pop a: push a,a (duplicates top element)
        if stack[0]>=0:
            if stack[0]<13:
                candidates.append(chr_cp437(0x21)) #  (!): pop a: push a! (factorial(a))
                candidates.append(chr_cp437(0xD1)) #  (╤): pop a: push 10**a
            if stack[0]<32:
                candidates.append(chr_cp437(0xD3)) #  (╙): pop a: push 2**a
                candidates.append(chr_cp437(0xB9)) #  (╣): pop a: push the ath row in Pascal's triangle
            if stack[0]<100:
                candidates.append(chr_cp437(0x46)) #  (F): pop a: push Fib(a) (Fib(0)=0, Fib(1)=Fib(2)=1); pop [a]: push a[0]
                candidates.append(chr_cp437(0x50)) #  (P): pop a: push the a-th prime (zero-indexed)
            if stack[0]<500 and plen<MAXLEN-1:
                candidates.append(chr_cp437(0x72)) #  (r): pop a: push [0,1,...,a-1] (range(0,a))


    if slen>0 and isinstance( stack[0], float ):
        candidates = candidates + [
            chr_cp437(0x4B), #  (K): pop a: push ceil(a)
            chr_cp437(0x4C)  #  (L): pop a: push floor(a)
        ]

    if slen>0 and isinstance( stack[0], list ) and len(stack[0])>0:
        candidates = candidates + [
            chr_cp437(0xE3), #  (π): pop [a]: push product([a])
            chr_cp437(0xE4)  #  (Σ): pop [a]: push sum([a])
        ]
        candidates.append(chr_cp437(0x69)) #  (i): pop [a]: push each element from [a], starting from end (flatten)
        if plen<MAXLEN-2:
            candidates.append(chr_cp437(0x0B)) #  (♂): take the next command and map it over the top of the stack (for example, ♂A is equivalent to `A`M)

    if slen>1:
        candidates.append(chr_cp437(0x6B)) #  (k): pop all elements from stack, convert to list (in the order they were on the stack, starting from the top), and push

    if slen>1 and isinstance( stack[0], int ):
        candidates = candidates + [
            chr_cp437(0x61), #  (a): invert the stack ([a,b,c,d] -> [d,c,b,a])
            chr_cp437(0xC5), #  (┼): duplicate each element on stack ([a,b,c] => [a,a,b,b,c,c])
            chr_cp437(0xC7)  #  (╟): pop a: pop a elements and push a list containing those elements in their original order
        ]
        if stack[0]<100:
            candidates.append(chr_cp437(0xC6)) #  (╞): pop a: make a total copies of each element on stack (3 [a,b,c] -> [a,a,a,b,b,b,c,c,c])     

    if slen>1 and isinstance( stack[0], int ) and isinstance( stack[1], int ):
        candidates = candidates + [
            chr_cp437(0x2A), #  (*): pop a,b: push a*b; pop a,[b] or [b],a: apply a* to each element in the array; pop [a],[b]: push dot product of [a] and [b] (sum([a[i]*b[i] for i in len(a)])) (shorter is padded with 0s)
            chr_cp437(0x2B), #  (+): pop a,b: push a+b; pop [a],[b]: push [a][b] (append [b] to [a]); pop a,[b] or [b],a: apply a+ to each element in the array
            chr_cp437(0x2D), #  (-): pop a,b: push a-b; pop [a],[b]: push [a]-[b] (all elements of [a] not in [b])
            chr_cp437(0x2F), #  (/): pop a,b: push a/b (float division); pop [a]: rotate [a] right by 1, push [a]
            chr_cp437(0x5C), #  (\): pop a,b: push a/b (integer division); pop [a]: rotate [a] left by 1, push [a]
        ]
        if stack[0]>1 and stack[0]<int(math.pow(MAX,1.0/3))+1 and stack[1]>2 and stack[1]<int(math.log(MAX)/math.log(3))+1:
            candidates.append(chr_cp437(0xFC))  #  (ⁿ): pop a,b: push pow(a,b)
        if stack[0]>2 and stack[0]<1000 and stack[1]>2 and stack[1]<stack[0]:
            candidates = candidates + [
                chr_cp437(0xDB), #  (█): pop a,b: push C(a,b) (aCb)
                chr_cp437(0xDC) #  (▄): pop a,b: push P(a,b) (aPb)
            ]
        if stack[1]-stack[0]>0 and stack[1]-stack[0]<500:
            candidates.append(chr_cp437(0x78)) #  (x): pop a,b: push [a,b) (range(a,b)); pop [a]: push range(*a)

    if slen>1 and (isinstance( stack[0], list ) or isinstance( stack[1], list )):
        candidates = candidates + [
            chr_cp437(0x2A), #  (*): pop a,b: push a*b; pop a,[b] or [b],a: apply a* to each element in the array; pop [a],[b]: push dot product of [a] and [b] (sum([a[i]*b[i] for i in len(a)])) (shorter is padded with 0s)
            chr_cp437(0x2B), #  (+): pop a,b: push a+b; pop [a],[b]: push [a][b] (append [b] to [a]); pop a,[b] or [b],a: apply a+ to each element in the array
            chr_cp437(0x2D), #  (-): pop a,b: push a-b; pop [a],[b]: push [a]-[b] (all elements of [a] not in [b])
            chr_cp437(0x2F), #  (/): pop a,b: push a/b (float division); pop [a]: rotate [a] right by 1, push [a]
            chr_cp437(0x5C), #  (\): pop a,b: push a/b (integer division); pop [a]: rotate [a] left by 1, push [a]
        ]

    return candidates

# p = "8"+chr_cp437(0x72)+chr_cp437(0x0B)
# res = Seriously().eval(p)
# print(p)
# print(res)
# print(next_instruction(p,res))
# sys.exit()

programs = [[['',None]]]
best = {}

def l(n,force_colon=False):
    if force_colon:
        return ':'+str(n)
    if n>=0 and n<10:
        return str(n)
    elif n<0 and n>-10:
        return str(-n)+'±'
    return ':'+str(n)

def cand(n,rep):
    # print(n,rep,len(rep),l(n),len(l(n)),best[n] if n in best else "")
    if n<=MAX and n>=-MAX and (len(rep)==1 or len(rep)<len(l(n))) and (n not in best or len(rep)<len(best[n])):
        best[n] = rep
        # print("woot")
        return True
    return False

for proglen in range(0,MAXLEN+1):
    print(proglen,"/",MAXLEN)
    if proglen<MAXLEN:
        programs.append([])
    first = ""
    for p in programs[proglen]:
        try:
            if first!=p[0][0]:
                first=p[0][0]
                print(" ",p[0][0],"/",9)
        except:
            pass
        if chr_cp437(0x7E) in p[0]:
            print(p[0])
        now = time.clock()
        try:
            res = Seriously().eval(p[0])
            elapsed = time.clock()-now
            if elapsed>0.0005:
                timed = timeit.timeit('Seriously().eval("'+str(p[0].encode('unicode_escape'))+'")','from seriously import Seriously',number=1000)
                if elapsed>0.01:
                    print("SLOW:")
                    print(p[0])
                    print(res)
                    print(elapsed)
            if chr_cp437(0x7E) in p[0]:
                print(res)
            if len(res)==1 and isinstance( res[0], int ):
                # print("cand",res[0],p[0])
                cand(res[0],p[0])
            p[1] = res
            if proglen<MAXLEN:
                # bail out if the stack is too complex to collapse in time
                if proglen==MAXLEN-1:
                    if len(res)>0 and isinstance( res[0], list ) and not isinstance( res[0][0], int ):
                        continue
                    if len(res)>1 and isinstance( res[0], list ):
                        continue
                    if len(res)>2:
                        continue
                for c in next_instruction(p[0],res):
                    programs[proglen+1].append([p[0]+c,None])
        except:
            pass

# print(programs)

def best_or_l(n,force_colon=False):
    if n in best:
        return best[n]
    if n<0 and -n in best:
        return best[-n]+chr_cp437(0xF1)
    return l(n,force_colon)

# for key,value in sorted(best.items()):
#     # if random.random()<0.01:
#     print(key,value)

score = 0
for i in [-2124910654, -2117700574, -2098186988, -2095671996, -2083075613, -2058271687, -2052250777, -2024215903, -2019485642, -2016095616, -2009838326, -2009173317, -2007673992, -2000014444, -1999825668, -1992515610, -1989566707, -1975506037, -1955473208, -1950731112, -1949886423, -1920624450, -1918465596, -1916287469, -1905036556, -1903956118, -1888944417, -1865221863, -1856600057, -1842797147, -1835637734, -1812631357, -1805740096, -1798015647, -1726688233, -1723609647, -1713776890, -1700307138, -1687644479, -1645515069, -1617635994, -1610444000, -1579053372, -1556891649, -1549652116, -1537732956, -1535180388, -1527162056, -1524851611, -1524658412, -1523244369, -1521379172, -1520191198, -1519035741, -1516978241, -1508892332, -1489938422, -1482102944, -1481823232, -1470621147, -1469145091, -1446844485, -1441790509, -1437843276, -1435359182, -1434186947, -1429816311, -1429393781, -1419752032, -1400387846, -1385152926, -1372620863, -1369257355, -1361933674, -1360480816, -1334846204, -1323741718, -1323660173, -1312800992, -1308824840, -1304658551, -1287829999, -1283767920, -1276288210, -1264275838, -1263965596, -1262866901, -1255421887, -1251428680, -1244825786, -1243200329, -1235305532, -1233977691, -1220537074, -1214100716, -1199414474, -1190725823, -1190401800, -1178717689, -1172378149, -1147869245, -1142875190, -1138538768, -1137864183, -1124917489, -1102987222, -1095920186, -1083001017, -1080902655, -1047122002, -1031842676, -1029877334, -1020849489, -1001684838, -998419619, -990915088, -985235989, -982515261, -979074894, -974195629, -973832940, -965324937, -944246431, -938387588, -933873331, -932692878, -928039285, -927947459, -914008773, -907981688, -906376330, -903502449, -898112547, -887444438, -862658502, -843628573, -822463032, -786051095, -776932426, -776033951, -752042328, -746532472, -743149468, -740225710, -734414418, -725435852, -708101516, -699674783, -694869277, -693246525, -690571518, -689249770, -688581912, -686864294, -681445866, -647992869, -641101583, -631409299, -624686189, -613079884, -593711206, -591688546, -591331185, -574790069, -573024823, -565387051, -565137163, -556338668, -556291492, -541411509, -538932064, -500479857, -482419890, -468050561, -424532545, -420534171, -408741873, -406973874, -387664799, -382084509, -367095703, -352332569, -352195997, -346430007, -324596389, -320119776, -306594578, -305952425, -283718911, -267302378, -243302738, -242955859, -232180029, -225394407, -217418127, -212286453, -208344820, -191300139, -186177744, -175765723, -161763935, -157025501, -140389149, -132298608, -126175769, -70566352, -68748576, -53985905, -52674668, -50228620, -39678495, -19825663, -8349922, -8186722, -8125700, -8073135, -8043230, -7994382, -7874433, -7863624, -7784916, -7782477, -7696343, -7607278, -7531250, -7388060, -7368780, -7367625, -7353084, -7334489, -7281141, -7267149, -7140057, -7119066, -7010389, -6992089, -6975258, -6863360, -6784772, -6741079, -6585985, -6550401, -6520011, -6495144, -6459702, -6294273, -6178342, -6169344, -6139663, -6090928, -6022637, -5992707, -5971334, -5925304, -5880940, -5873707, -5807953, -5703992, -5692895, -5535131, -5488812, -5468330, -5404148, -5290247, -5274221, -5264144, -5234715, -5224048, -5179837, -5084014, -5043990, -5028537, -5011679, -4998333, -4922901, -4880159, -4874060, -4787390, -4749096, -4736217, -4502308, -4480611, -4424319, -4363262, -4349743, -4290050, -4240069, -4239657, -4174072, -4093051, -4045363, -4037689, -4033352, -3839265, -3766343, -3716899, -3680075, -3679053, -3581776, -3539227, -3461158, -3282526, -3205947, -3183427, -3169708, -3166430, -3089822, -3061531, -2947574, -2930733, -2919246, -2872882, -2830770, -2739228, -2713826, -2634018, -2613990, -2525529, -2439507, -2432921, -2376201, -2335005, -2307524, -2265548, -2176176, -2123133, -2108773, -2105934, -2075032, -2073940, -2045837, -2045648, -1978182, -1945769, -1935486, -1881608, -1654650, -1602520, -1506746, -1505294, -1475309, -1457605, -1327259, -1312217, -1178723, -1027439, -880781, -833776, -666675, -643098, -593446, -468772, -450369, -443225, -418164, -402004, -319964, -307400, -279414, -190199, -176644, -66862, -32745, -32686, -32352, -32261, -32035, -31928, -31414, -31308, -30925, -30411, -29503, -29182, -28573, -28500, -28093, -27743, -27716, -27351, -27201, -26834, -25946, -25019, -24469, -24341, -24292, -24151, -23732, -22769, -22242, -22002, -20863, -20762, -20644, -20189, -20009, -19142, -19036, -18980, -18616, -18196, -18123, -17942, -17915, -17601, -17494, -16669, -16417, -16317, -15051, -14796, -14742, -14600, -14443, -14159, -14046, -13860, -13804, -13745, -13634, -13498, -13497, -12688, -12471, -12222, -11993, -11467, -11332, -10783, -10250, -10114, -10089, -9930, -9434, -9336, -9128, -9109, -8508, -8460, -8198, -8045, -7850, -7342, -7229, -6762, -6302, -6245, -6171, -5957, -5842, -4906, -4904, -4630, -4613, -4567, -4427, -4091, -4084, -3756, -3665, -3367, -3186, -2922, -2372, -2331, -1936, -1683, -1350, -1002, -719, -152, -128, -127, -124, -122, -121, -119, -116, -113, -112, -111, -107, -104, -102, -101, -100, -95, -94, -91, -90, -87, -81, -80, -79, -78, -73, -72, -69, -68, -66, -65, -63, -57, -54, -52, -51, -48, -47, -46, -45, -43, -41, -37, -33, -31, -30, -27, -25, -21, -18, -15, -12, -8, -1, 0, 1, 3, 4, 5, 6, 11, 14, 17, 23, 25, 26, 27, 28, 29, 31, 32, 39, 41, 46, 49, 51, 52, 56, 58, 61, 64, 66, 67, 70, 74, 79, 80, 86, 88, 89, 92, 93, 99, 102, 104, 109, 113, 117, 120, 122, 123, 127, 695, 912, 1792, 2857, 3150, 3184, 4060, 4626, 5671, 6412, 6827, 7999, 8017, 8646, 8798, 9703, 9837, 10049, 10442, 10912, 11400, 11430, 11436, 11551, 11937, 12480, 13258, 13469, 13689, 13963, 13982, 14019, 14152, 14259, 14346, 15416, 15613, 15954, 16241, 16814, 16844, 17564, 17702, 17751, 18537, 18763, 19890, 21216, 22238, 22548, 23243, 23383, 23386, 23407, 23940, 24076, 24796, 24870, 24898, 24967, 25139, 25176, 25699, 26167, 26536, 26614, 27008, 27087, 27142, 27356, 27458, 27800, 27827, 27924, 28595, 29053, 29229, 29884, 29900, 30460, 30556, 30701, 30815, 30995, 31613, 31761, 31772, 32099, 32308, 32674, 75627, 80472, 103073, 110477, 115718, 172418, 212268, 242652, 396135, 442591, 467087, 496849, 675960, 759343, 846297, 881562, 1003458, 1153900, 1156733, 1164679, 1208265, 1318372, 1363958, 1411655, 1522329, 1559609, 1677118, 1693658, 1703597, 1811223, 1831642, 1838628, 1884144, 1931545, 2085504, 2168156, 2170263, 2239585, 2308894, 2329235, 2364957, 2432335, 2435551, 2596936, 2684907, 2691011, 2705195, 2738057, 2851897, 2925289, 2995414, 3051534, 3216094, 3267022, 3271559, 3338856, 3440797, 3638325, 3651369, 3718696, 3724814, 3811069, 3854697, 3866969, 3893228, 3963455, 3984546, 4098376, 4100957, 4128113, 4200719, 4256344, 4286332, 4306356, 4316314, 4438803, 4458063, 4461638, 4552228, 4563790, 4584831, 4607992, 4884455, 4907501, 5045419, 5066844, 5150624, 5157161, 5190669, 5314703, 5337397, 5434807, 5440092, 5502665, 5523089, 5547122, 5566200, 5582936, 5634068, 5690330, 5776984, 5778441, 5818505, 5826687, 5827184, 5885735, 6010506, 6084254, 6131498, 6138324, 6250773, 6292801, 6306275, 6315242, 6331640, 6484374, 6502969, 6545970, 6666951, 6690905, 6763576, 6766086, 6895048, 6912227, 6929081, 6941390, 6978168, 7045672, 7085246, 7193307, 7197398, 7270237, 7276767, 7295790, 7375488, 7472098, 7687424, 7840758, 7880957, 7904499, 7948678, 7974126, 8015691, 8037685, 8112955, 8131380, 8140556, 8142384, 8220436, 8308817, 8331317, 22581970, 45809129, 48103779, 78212045, 79674901, 97299830, 110308649, 131744428, 136663461, 138485719, 139842794, 152061792, 152685704, 153070991, 156228213, 164884737, 174776199, 189346581, 193148547, 208582124, 223891881, 227308187, 237373798, 241214067, 242476929, 245495851, 260606593, 275202667, 285717038, 317009689, 322759532, 325369206, 339724742, 340122632, 345010859, 352375176, 355826263, 359695034, 366118516, 370008270, 382712922, 386379440, 401153345, 404986391, 426084981, 442843409, 473909474, 475192613, 492302667, 494747879, 506279889, 509813998, 537558350, 548423414, 548467404, 566383324, 574188786, 574792333, 591678147, 596558084, 597423476, 602432742, 603067874, 629552047, 630893263, 635249783, 644959276, 650710927, 664859367, 669433203, 684329599, 699991513, 714451929, 723556530, 739294558, 750895264, 757618344, 781123405, 796973385, 801637715, 804776709, 829003666, 829219068, 840167037, 854882202, 860066192, 864304878, 864808449, 867107161, 871871263, 880591851, 883020336, 883178082, 920223781, 936008673, 939417822, 956776353, 958281059, 962183717, 964059257, 967860573, 974322643, 974999286, 980009921, 1032949015, 1044249483, 1064892676, 1075628270, 1080848022, 1085571657, 1173635593, 1174809080, 1176744978, 1209783795, 1212074975, 1252323507, 1254757790, 1301450562, 1302240953, 1314501797, 1315121266, 1339304157, 1364304289, 1376260506, 1383883477, 1395158643, 1411117754, 1440755058, 1448365702, 1466814914, 1468433821, 1490105126, 1493912601, 1495600372, 1509536621, 1511014977, 1545693948, 1548924199, 1566583103, 1569747154, 1574097219, 1597784674, 1610710480, 1618324005, 1646105187, 1649417465, 1655649169, 1660619384, 1668826887, 1671093718, 1672456990, 1673477565, 1678638502, 1682302139, 1682515769, 1687920300, 1690062315, 1706031388, 1713660819, 1772170709, 1778416812, 1833443690, 1861312062, 1876004501, 1876358085, 1882435551, 1916050713, 1944906037, 1950207172, 1951593247, 1973638546, 1976288281, 1994977271, 2020053060, 2025281195, 2029716419, 2033980539, 2052482076, 2058251762, 2069273004, 2073978021, 2111013213, 2119886932, 2134609957, 2140349794, 2143934987]:
    print(i,best_or_l(i,True),len(l(i)),len(best_or_l(i,True)))
    score = score + (len(l(i))-len(best_or_l(i,True)))
print("Score:",score)

with open("brute_serious.json","w") as outfile:
    outfile.write(json.dumps(best,sort_keys=True,indent=2))

यहाँ वास्तव में इस एल्गोरिथम द्वारा पाए जाने वाले कार्यक्रमों के प्रकारों का एक यादृच्छिक नमूना है:

-387420483 99ⁿ6-
-16777208 4!╙8-
-999999 6╤1-
-362864 9!4²-
-46369 4!Fu±
-5045 57!±-
8101 9eL¬
19900 2╤τrΣ
46367 4!FD
68072 5╙│F\
99990 1╤5╤-
156246 75ⁿ¬τ
518393 76!²-
1814399 59!*D
6534927 35╙F*
14930357 56²F+
19999995 57╤τ-
25396560 7!│D*
65691025 9eKu²
100001000 3╤8╤+
200000002 8╤uτ
800000008 88╤u*
1626347584 88!+²
2000000018 99╤+τ

4

रूबी, 52 चरस बच गई

इसी तरह के सवाल के जवाब के आधार पर । यह एक नंबर पाने के तरीकों की एक बड़ी सूची बनाता है और सबसे कम का चयन करता है। पोस्ट किए गए अन्य उत्तरों के विपरीत, यह अपनी छोटी बचत पर अधिकांश बचत प्राप्त करता है। वास्तव में मैं 2000 से अधिक पूर्ण मूल्यों के साथ संख्याओं की कोशिश नहीं करता।

$s = {};
Fact = [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880]
Fib = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733, 1134903170, 1836311903]
Prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999]
def shortest a,b=nil
    return $s[[a,b]] if $s[[a,b]]
    return $s[[a,b]] = ":#{a}" if (b||a).abs > 2000 #gives up on big inputs
    $s[[a,b]] = ":#{a}" #set a temp value to block calling with the same paramiters recursivly.
    l = []
    if b
        if a == b
            return $s[[a,b]] = ""
        elsif a > b
            l.push shortest(a-b)+"-"
            l.push "X"+shortest(b)
            l.push "¬" if b+2==a
            l.push "D" if b+1==a
        elsif a < b
            l.push shortest(b-a)+"+"
            l.push "²"+shortest(a*a,b) if a*a>a && a*a<=b+2
            l.push "τ"+shortest(a+a,b) if a+a<=b+2 && a+a>a
            l.push shortest(b/a)+"*" if a>2 && b%a == 0
            l.push ";"+shortest(a,b/a)+"*" if a>2 && b%a == 0
            l.push "╙"+shortest(2**a,b) if 2**a<=b+2
            l.push "╤"+shortest(10**a,b) if 10**a<=b+2
            l.push "F"+shortest(Fib[a],b) if Fib[a] and Fib[a]<=b+2 and a > 5
            l.push "P"+shortest(Prime[a],b) if Prime[a] and Prime[a]<=b+2
            l.push "!"+shortest(Fact[a],b) if Fact[a] and Fact[a]<=b+2 and a > 3
        end
    else
        return ($s[[a,b]] = a.to_s) if a<10 and a>-1
        l.push ":#{a}"
        if a<0
            l.push shortest(-a)+"±" 
            l.push shortest(~a)+"~"
            l.push shortest(a+1)+"D"
            l.push shortest(a+2)+"¬"
        else
            l.push shortest(a-1)+"u" 
            l.push shortest(a-2)+"⌐"
            (1..[a/2,100].min).each {|n|
                l.push shortest(n)+shortest(n,a)
            }
        end
    end
    return $s[[a,b]] = l.min_by{|x|x.length}
end

a = [-4427,-4091,-4084,-3756,-3665,-3367,-3186,-2922,-2372,-2331,-1936,-1683,-1350,-1002,-719,-152,-128,-127,-124,-122,-121,-119,-116,-113,-112,-111,-107,-104,-102,-101,-100,-95,-94,-91,-90,-87,-81,-80,-79,-78,-73,-72,-69,-68,-66,-65,-63,-57,-54,-52,-51,-48,-47,-46,-45,-43,-41,-37,-33,-31,-30,-27,-25,-21,-18,-15,-12,-8,-1,0,1,3,4,5,6,11,14,17,23,25,26,27,28,29,31,32,39,41,46,49,51,52,56,58,61,64,66,67,70,74,79,80,86,88,89,92,93,99,102,104,109,113,117,120,122,123,127,695,912,1792,2857,3150,3184,4060,4626,5671,6412,6827,7999,8017]
a.sort_by!{|x|x.abs}
c = a.map{
    |i|
    p [i,shortest(i)]
    shortest(i)
}
p c.inject(0){|a,b|a+b.length}

और सभी संक्षिप्त संख्याओं की एक पूरी सूची (निरपेक्ष मूल्य द्वारा क्रमबद्ध):

[0, "0"]
[-1, "1±"]
[1, "1"]
[3, "3"]
[4, "4"]
[5, "5"]
[6, "6"]
[-8, "8±"]
[11, "9⌐"]
[-12, "6τ±"]
[14, "7τ"]
[-15, "7τ~"]
[17, "6P"]
[-18, "9τ±"]
[-21, "8F±"]
[23, "8P"]
[25, "5²"]
[-25, "5²±"]
[29, "9P"]
[-30, "9P~"]
[32, "5╙"]
[-33, "5╙~"]
[-37, "6²~"]
[49, "7²"]
[64, "6╙"]
[-65, "6╙~"]
[-81, "9²±"]
[-100, "2╤±"]
[-101, "2╤~"]
[-102, "2╤⌐±"]
[102, "2ѩ"]
[113, "9PP"]
[-113, "9PP±"]
[-119, "5!D±"]
[120, "5!"]
[-121, "5!~"]
[122, "5!⌐"]
[-122, "5!⌐±"]
[127, "7╙D"]
[-127, "7╙D±"]
[-128, "7╙±"]
[-719, "6!D±"]
[-1002, "3╤⌐±"]
[-1683, "9P²τ~"]
[1792, "78╙*"]
[-1936, ":44²±"]

नोट: इनका बीन परीक्षण नहीं किया गया है क्योंकि मेरे पास वास्तव में पहुंच नहीं है।


मैंने जल्दी से ध्यान दिया कि आप ~ का उपयोग कर रहे हैं और मैं नहीं, जो बाइट के एक जोड़े को बचाता है। मैंने यह पता लगाने में 30 मिनट बिताए कि छोटी संख्या के लिए आपका स्कोर बेहतर क्यों था जब मुझे एक मुट्ठी मिल जाए जो आप नहीं करते हैं। मुझे अंततः एहसास हुआ कि मैं 0-9 के लिए 0-9 के रूप में तुच्छ मामले की गिनती कर रहा था, न कि: 0-: 9। तीनों समाधानों पर स्वयं 6 अंक खर्च करें। मुझे इसकी जाँच करने के लिए धन्यवाद।
स्पर्म

@sparr मुझे लग रहा था कि इससे आपको बेहतर प्रदर्शन करने में मदद मिलेगी।
मेगाटॉम

4

पायथन 3, 52 55 बाइट्स बचाए गए

यह समाधान पिछले दो से पीछे की ओर काम करता है। दाएं से बाएं प्रोग्राम असेंबल करने के बजाय, मैं अंत में शुरू करता हूं और पीछे की ओर काम करता हूं। इस काम को करने के लिए, मुझे वास्तव में अपने कार्यक्रम चलाने हैं, और मैं उनके मापदंडों के आधार पर निर्देशों को prune नहीं कर सकता क्योंकि उनके पैरामीटर अभी तक मौजूद नहीं हैं जब मैंने उन्हें जोड़ा है। उसके लिए मेरा वर्कअराउंड इस उत्तर में मौजूद नहीं है; इसमें किसी भी समय पागलपन पैदा करने वाले कार्यों को बड़े तर्कों के साथ प्राप्त करने और उस अपवाद को उठाने के लिए SeriouslyCommands.py को बताना शामिल है, ताकि मैं इसे पकड़ सकूं।

यहां बताया गया है कि यह कार्यक्रम कैसे काम करता है:

मैं एक खाली स्टैक से शुरू करता हूं और जानता हूं कि मुझे एक ही नंबर चाहिए। क्या निर्देश उसे पूरा कर सकते हैं? 0-9 मुझे एक पूर्णांक मिलता है और स्टैक पर कुछ भी करने की आवश्यकता नहीं होती है, इसलिए वे पूर्ण कार्यक्रम हैं। के, एल, टी, ई और दूसरों का एक गुच्छा मुझे एक नंबर मिलता है और एक नंबर की आवश्यकता होती है (मैं आउटपुट की जाँच होने तक फ़्लोट्स और इनट्स के बीच अंतर नहीं करता)। *, +, आदि दो संख्याओं को एक संख्या में बदलते हैं। और इसी तरह।

अब मेरे पास कुछ पूर्ण कार्यक्रम और अधूरे प्रोग्राम-प्रत्यय की एक सूची है जो स्टैक पर कुछ प्रकार की ज्ञात व्यवस्था को मेरी इच्छित संख्या में बदल सकती है। प्रक्रिया को दोहराएं और प्रत्येक निर्देश को उन सभी को प्रस्तुत करें, जो अपनी आवश्यकताओं को पूरा करने के लिए एक / कुछ / सभी को पूरा कर सकते हैं, जो पूरे कार्यक्रम हैं, उन्हें बचाएं और अधूरे वाले को अगले चरण पर भेजें।

पिछले दो चरणों में मैं संभावनाओं को बहुत अधिक पसंद करता हूं क्योंकि मुझे पता है कि जब मैं कर चुका होता हूं तो मेरे पास कोई स्टैक आवश्यकताएं नहीं रह सकती हैं (इसलिए 0-9 कार्यक्रम के अंतिम चरण में आने के लिए केवल वैध निर्देश हैं) और उससे पहले मेरे पास आवश्यकता के रूप में केवल एक ही संख्या हो सकती है।

आश्चर्य की बात नहीं, यह समाधान वास्तव में मेरे अन्य दो समाधानों के समान स्कोर का निर्माण करता है। वे परिणामों के लगभग एक ही सेट पाते हैं।

यह कार्यक्रम संभवतः अन्य की तुलना में कम समय में 6 वर्णों तक जा सकता है, लेकिन यह अभी भी निषेधात्मक होगा।

मुझे लगता है कि दोनों को मिलाकर, उपसर्गों और प्रत्ययों को जोड़कर और उनके ढेर संगत होने पर एक महान समाधान बनाया जा सकता है।

#!/usr/bin/env python3
# -*- coding: cp437 -*-

import os
import sys
import json
import math
import time
import random
import timeit

#!/usr/bin/env python3
# -*- coding: cp437 -*-

# instruction, pops, pushes, 
instructions = [
    [0x30, [], ['number']], #  (0): push 0
    [0x31, [], ['number']], #  (1): push 1
    [0x32, [], ['number']], #  (2): push 2
    [0x33, [], ['number']], #  (3): push 3
    [0x34, [], ['number']], #  (4): push 4
    [0x35, [], ['number']], #  (5): push 5
    [0x36, [], ['number']], #  (6): push 6
    [0x37, [], ['number']], #  (7): push 7
    [0x38, [], ['number']], #  (8): push 8
    [0x39, [], ['number']], #  (9): push 9

    [0x4B, ['number'], ['number']], #  (K): pop a: push ceil(a)
    [0x4C, ['number'], ['number']], #  (L): pop a: push floor(a)

    [0x54, ['number'], ['number']], #  (T): pop a: push tan(a); pop [a],b,c: set [a][b] to c, push [a]
    [0x65, ['number'], ['number']], #  (e): pop a: push exp(a)

    [0xAB, ['number'], ['number']], #  (½): pop a: push a/2 (float division)
    [0xAC, ['number'], ['number']], #  (¼): pop a: push a/4 (float division)

    [0x21, ['number'], ['number']], #  (!): pop a: push a! (factorial(a))
    [0x44, ['number'], ['number']], #  (D): pop a: push a-1; pop [a]: push stddev([a])
    [0x46, ['number'], ['number']], #  (F): pop a: push Fib(a) (Fib(0)=0, Fib(1)=Fib(2)=1); pop [a]: push a[0]
    [0x50, ['number'], ['number']], #  (P): pop a: push the a-th prime (zero-indexed)
    [0x75, ['number'], ['number']], #  (u): pop a: push a+1
    [0x7E, ['number'], ['number']], #  (~): pop a: push ~a (unary bitwise negate)
    [0xA9, ['number'], ['number']], #  (⌐): pop a: push a+2
    [0xAA, ['number'], ['number']], #  (¬): pop a: push a-2
    [0xD1, ['number'], ['number']], #  (╤): pop a: push 10**a
    [0xD3, ['number'], ['number']], #  (╙): pop a: push 2**a
    [0xE7, ['number'], ['number']], #  (τ): pop a: push 2*a
    [0xF1, ['number'], ['number']], #  (±): pop a: push -a (unary negate)
    [0xFD, ['number'], ['number']], #  (²): pop a: push a*a

    [0x2A, ['number','number'], ['number']], #  (*): pop a,b: push a*b; pop a,[b] or [b],a: apply a* to each element in the array; pop [a],[b]: push dot product of [a] and [b] (sum([a[i]*b[i] for i in len(a)]) (shorter is padded with 0s)
    [0x2B, ['number','number'], ['number']], #  (+): pop a,b: push a+b; pop [a],[b]: push [a][b] (append [b] to [a]); pop a,[b] or [b],a: apply a+ to each element in the array
    [0x2D, ['number','number'], ['number']], #  (-): pop a,b: push a-b; pop [a],[b]: push [a]-[b] (all elements of [a] not in [b])
    [0x2F, ['number','number'], ['number']], #  (/): pop a,b: push a/b (float division); pop [a]: rotate [a] right by 1, push [a]
    [0x5C, ['number','number'], ['number']], #  (\): pop a,b: push a/b (integer division); pop [a]: rotate [a] left by 1, push [a]
    [0xFC, ['number','number'], ['number']], #  (ⁿ): pop a,b: push pow(a,b)

    [0xDB, ['number','number'], ['number']], #  (█): pop a,b: push C(a,b) (aCb)
    [0xDC, ['number','number'], ['number']], #  (▄): pop a,b: push P(a,b) (aPb)

    [0x3B, ['number'], ['number','number']], #  (;): pop a: push a,a (duplicates top element)

    [0xE3, ['list'], ['number']], #  (π): pop [a]: push product([a])
    [0xE4, ['list'], ['number']], #  (Σ): pop [a]: push sum([a])

    [0x69, ['list'], ['numbers']], #  (i): pop [a]: push each element from [a], starting from end (flatten)

    [0xC6, ['numbers'], ['numbers']], #  (╞): pop a: make a total copies of each element on stack (3 [a,b,c] -> [a,a,a,b,b,b,c,c,c])     

    [0xC7, ['numbers'], ['list']], #  (╟): pop a: pop a elements and push a list containing those elements in their original order

    [0x0B, ['list'], ['list']], #  (♂): take the next command and map it over the top of the stack (for example, ♂A is equivalent to `A`M)

    [0x61, ['numbers'], ['numbers']], #  (a): invert the stack ([a,b,c,d] -> [d,c,b,a])
    [0xB3, ['numbers'], ['numbers']], #  (│): duplicate stack ([a,b,c] => [a,b,c,a,b,c])
    [0xC5, ['numbers'], ['numbers']], #  (┼): duplicate each element on stack ([a,b,c] => [a,a,b,b,c,c])

    [0x72, ['number'], ['list']], #  (r): pop a: push [0,1,...,a-1] (range(0,a))
    [0xB9, ['number'], ['list']], #  (╣): pop a: push the ath row in Pascal's triangle

    [0x78, ['number','number'], ['list']], #  (x): pop a,b: push [a,b) (range(a,b)); pop [a]: push range(*a)
    [0x78, ['list'], ['list']], #  (x): pop a,b: push [a,b) (range(a,b)); pop [a]: push range(*a)

    [0x6B, ['numbers'], ['list']],#  (k): pop all elements from stack, convert to list (in the order they were on the stack, starting from the top) and push

    # 0x3A, #  (:): numeric literal delimiter: pushes the longest string of characters in '0123456789+-.ij' as a numeric
    # 0x4D, #  (M): pop f,[a], execute f for each element in [a], using the element as a temporary stack, push [a] (similar to map(f,[a])); pop [a]: push max([a])
    # 0x52, #  (R): pop f,[a]: call f, using [a] as a temporary stack, push [a] (similar to reduce(f,[a])); pop [a]: push [a][::-1] (reverse); pop a: push [1,2,...,a] (range(1,a+1))
    # 0x57, #  (W): loop delimiter: peek top of stack, repeat code in loop while a evaluates to true
    # 0x60, #  (`): function literal delimiter, pushes function whose body contains all of the commands until the next `. An implied ` is present at EOF if needed.
]

provides = {
    'number':[],
    'numbers':[],
    'list':[]
    }

wants = [[]]*256

for i in instructions:
    wants[i[0]] = i[1]
    provides[i[2][0]].append(i[0])

from seriously import Seriously,chr_cp437,ord_cp437

MAX=2**31

# returns ([finished programs],[new programs]), one of which will be empty
def extend_program(p):
    finished_programs=[]
    new_programs=[]
    # print(p)
    for i in provides[p[1][-1]]:
        new_p = chr_cp437(i)+p[0]
        new_wants = p[1][:-1]+wants[i]
        if new_wants==[]: # we've reached a complete program! run it
            # print(p[0])
            now = time.clock()
            # print(p[0])
            try:
                res = Seriously().eval(new_p)
            except:
                return ([],[])
            # print(res)
            elapsed = time.clock()-now
            if elapsed>0.001:
                try:
                    elapsed = timeit.timeit('Seriously().eval("'+str(new_p.encode('unicode_escape'))+'")','from seriously import Seriously',number=1000)
                except:
                    continue
                if elapsed>0.005:
                    print("SLOW:")
                    print(new_p)
                    print(res)
                    print(elapsed)
            # print(res)
            finished_programs.append([new_p,res])
            continue
        if len(new_p)==MAXLEN and new_wants!=[]: # no room left to fulfill any wants
            continue
        if len(new_p)==MAXLEN-1 and new_wants != ['number']: # no room left to fulfill complex wants
            continue
        new_programs.append([new_p,new_wants])
    if len(p[1])>1 and p[1][-1]=='number' and p[1][-2]=='number':
        for i in provides['numbers']:
            new_p = chr_cp437(i)+p[0]
            old_wants = p[1]
            while len(p[1]) and p[1][-1]=='number':
                p[1].pop()
            new_wants = old_wants+wants[i]
            if len(new_p)==MAXLEN and new_wants!=[]:
                continue
            if len(new_p)==MAXLEN-1 and \
                new_wants != ['list'] and \
                new_wants != ['number'] and \
                new_wants != ['numbers']:
                continue
            new_programs.append([new_p,new_wants])
    return (finished_programs,new_programs)

unfinished_programs = [['',['number']]]
best = {}

def l(n,force_colon=False):
    if force_colon:
        return ':'+str(n)
    if n>=0 and n<10:
        return str(n)
    elif n<0 and n>-10:
        return str(-n)+'±'
    return ':'+str(n)

def cand(n,rep):
    # print(n,rep,len(rep),l(n),len(l(n)),best[n] if n in best else "")
    if n<=MAX and n>=-MAX and (len(rep)==1 or len(rep)<len(l(n))) and (n not in best or len(rep)<len(best[n])):
        best[n] = rep
        # print("woot")
        return True
    return False

MAXLEN = 5

for i in range(MAXLEN):
    print(i+1,"/",MAXLEN)
    new_unfinished_programs = []
    c = ''
    for p in unfinished_programs:
        if len(p[0]) and p[0][-1]!= c:
            print(c)
            c=p[0][-1]
        (finished_programs,new_programs) = extend_program(p)
        for f in finished_programs:
            # print(f[0])
            # print(f[1][0])
            if len(f[1])==0:
                # print("TOO MANY RESULTS")
                continue
            if isinstance(f[1][0],int):
                cand(f[1][0],f[0])
            # if isinstance(f[1][0],list):
                # print("LIST RESULT")
        new_unfinished_programs = new_unfinished_programs + new_programs
    unfinished_programs = new_unfinished_programs

def best_or_l(n,force_colon=False):
    if n in best:
        return best[n]
    if n<0 and -n in best:
        return best[-n]+"±"
    return l(n,force_colon)

for key,value in sorted(best.items()):
    # if random.random()<0.01:
    print(key,value)

score = 0
for i in [-2124910654, -2117700574, -2098186988, -2095671996, -2083075613, -2058271687, -2052250777, -2024215903, -2019485642, -2016095616, -2009838326, -2009173317, -2007673992, -2000014444, -1999825668, -1992515610, -1989566707, -1975506037, -1955473208, -1950731112, -1949886423, -1920624450, -1918465596, -1916287469, -1905036556, -1903956118, -1888944417, -1865221863, -1856600057, -1842797147, -1835637734, -1812631357, -1805740096, -1798015647, -1726688233, -1723609647, -1713776890, -1700307138, -1687644479, -1645515069, -1617635994, -1610444000, -1579053372, -1556891649, -1549652116, -1537732956, -1535180388, -1527162056, -1524851611, -1524658412, -1523244369, -1521379172, -1520191198, -1519035741, -1516978241, -1508892332, -1489938422, -1482102944, -1481823232, -1470621147, -1469145091, -1446844485, -1441790509, -1437843276, -1435359182, -1434186947, -1429816311, -1429393781, -1419752032, -1400387846, -1385152926, -1372620863, -1369257355, -1361933674, -1360480816, -1334846204, -1323741718, -1323660173, -1312800992, -1308824840, -1304658551, -1287829999, -1283767920, -1276288210, -1264275838, -1263965596, -1262866901, -1255421887, -1251428680, -1244825786, -1243200329, -1235305532, -1233977691, -1220537074, -1214100716, -1199414474, -1190725823, -1190401800, -1178717689, -1172378149, -1147869245, -1142875190, -1138538768, -1137864183, -1124917489, -1102987222, -1095920186, -1083001017, -1080902655, -1047122002, -1031842676, -1029877334, -1020849489, -1001684838, -998419619, -990915088, -985235989, -982515261, -979074894, -974195629, -973832940, -965324937, -944246431, -938387588, -933873331, -932692878, -928039285, -927947459, -914008773, -907981688, -906376330, -903502449, -898112547, -887444438, -862658502, -843628573, -822463032, -786051095, -776932426, -776033951, -752042328, -746532472, -743149468, -740225710, -734414418, -725435852, -708101516, -699674783, -694869277, -693246525, -690571518, -689249770, -688581912, -686864294, -681445866, -647992869, -641101583, -631409299, -624686189, -613079884, -593711206, -591688546, -591331185, -574790069, -573024823, -565387051, -565137163, -556338668, -556291492, -541411509, -538932064, -500479857, -482419890, -468050561, -424532545, -420534171, -408741873, -406973874, -387664799, -382084509, -367095703, -352332569, -352195997, -346430007, -324596389, -320119776, -306594578, -305952425, -283718911, -267302378, -243302738, -242955859, -232180029, -225394407, -217418127, -212286453, -208344820, -191300139, -186177744, -175765723, -161763935, -157025501, -140389149, -132298608, -126175769, -70566352, -68748576, -53985905, -52674668, -50228620, -39678495, -19825663, -8349922, -8186722, -8125700, -8073135, -8043230, -7994382, -7874433, -7863624, -7784916, -7782477, -7696343, -7607278, -7531250, -7388060, -7368780, -7367625, -7353084, -7334489, -7281141, -7267149, -7140057, -7119066, -7010389, -6992089, -6975258, -6863360, -6784772, -6741079, -6585985, -6550401, -6520011, -6495144, -6459702, -6294273, -6178342, -6169344, -6139663, -6090928, -6022637, -5992707, -5971334, -5925304, -5880940, -5873707, -5807953, -5703992, -5692895, -5535131, -5488812, -5468330, -5404148, -5290247, -5274221, -5264144, -5234715, -5224048, -5179837, -5084014, -5043990, -5028537, -5011679, -4998333, -4922901, -4880159, -4874060, -4787390, -4749096, -4736217, -4502308, -4480611, -4424319, -4363262, -4349743, -4290050, -4240069, -4239657, -4174072, -4093051, -4045363, -4037689, -4033352, -3839265, -3766343, -3716899, -3680075, -3679053, -3581776, -3539227, -3461158, -3282526, -3205947, -3183427, -3169708, -3166430, -3089822, -3061531, -2947574, -2930733, -2919246, -2872882, -2830770, -2739228, -2713826, -2634018, -2613990, -2525529, -2439507, -2432921, -2376201, -2335005, -2307524, -2265548, -2176176, -2123133, -2108773, -2105934, -2075032, -2073940, -2045837, -2045648, -1978182, -1945769, -1935486, -1881608, -1654650, -1602520, -1506746, -1505294, -1475309, -1457605, -1327259, -1312217, -1178723, -1027439, -880781, -833776, -666675, -643098, -593446, -468772, -450369, -443225, -418164, -402004, -319964, -307400, -279414, -190199, -176644, -66862, -32745, -32686, -32352, -32261, -32035, -31928, -31414, -31308, -30925, -30411, -29503, -29182, -28573, -28500, -28093, -27743, -27716, -27351, -27201, -26834, -25946, -25019, -24469, -24341, -24292, -24151, -23732, -22769, -22242, -22002, -20863, -20762, -20644, -20189, -20009, -19142, -19036, -18980, -18616, -18196, -18123, -17942, -17915, -17601, -17494, -16669, -16417, -16317, -15051, -14796, -14742, -14600, -14443, -14159, -14046, -13860, -13804, -13745, -13634, -13498, -13497, -12688, -12471, -12222, -11993, -11467, -11332, -10783, -10250, -10114, -10089, -9930, -9434, -9336, -9128, -9109, -8508, -8460, -8198, -8045, -7850, -7342, -7229, -6762, -6302, -6245, -6171, -5957, -5842, -4906, -4904, -4630, -4613, -4567, -4427, -4091, -4084, -3756, -3665, -3367, -3186, -2922, -2372, -2331, -1936, -1683, -1350, -1002, -719, -152, -128, -127, -124, -122, -121, -119, -116, -113, -112, -111, -107, -104, -102, -101, -100, -95, -94, -91, -90, -87, -81, -80, -79, -78, -73, -72, -69, -68, -66, -65, -63, -57, -54, -52, -51, -48, -47, -46, -45, -43, -41, -37, -33, -31, -30, -27, -25, -21, -18, -15, -12, -8, -1, 0, 1, 3, 4, 5, 6, 11, 14, 17, 23, 25, 26, 27, 28, 29, 31, 32, 39, 41, 46, 49, 51, 52, 56, 58, 61, 64, 66, 67, 70, 74, 79, 80, 86, 88, 89, 92, 93, 99, 102, 104, 109, 113, 117, 120, 122, 123, 127, 695, 912, 1792, 2857, 3150, 3184, 4060, 4626, 5671, 6412, 6827, 7999, 8017, 8646, 8798, 9703, 9837, 10049, 10442, 10912, 11400, 11430, 11436, 11551, 11937, 12480, 13258, 13469, 13689, 13963, 13982, 14019, 14152, 14259, 14346, 15416, 15613, 15954, 16241, 16814, 16844, 17564, 17702, 17751, 18537, 18763, 19890, 21216, 22238, 22548, 23243, 23383, 23386, 23407, 23940, 24076, 24796, 24870, 24898, 24967, 25139, 25176, 25699, 26167, 26536, 26614, 27008, 27087, 27142, 27356, 27458, 27800, 27827, 27924, 28595, 29053, 29229, 29884, 29900, 30460, 30556, 30701, 30815, 30995, 31613, 31761, 31772, 32099, 32308, 32674, 75627, 80472, 103073, 110477, 115718, 172418, 212268, 242652, 396135, 442591, 467087, 496849, 675960, 759343, 846297, 881562, 1003458, 1153900, 1156733, 1164679, 1208265, 1318372, 1363958, 1411655, 1522329, 1559609, 1677118, 1693658, 1703597, 1811223, 1831642, 1838628, 1884144, 1931545, 2085504, 2168156, 2170263, 2239585, 2308894, 2329235, 2364957, 2432335, 2435551, 2596936, 2684907, 2691011, 2705195, 2738057, 2851897, 2925289, 2995414, 3051534, 3216094, 3267022, 3271559, 3338856, 3440797, 3638325, 3651369, 3718696, 3724814, 3811069, 3854697, 3866969, 3893228, 3963455, 3984546, 4098376, 4100957, 4128113, 4200719, 4256344, 4286332, 4306356, 4316314, 4438803, 4458063, 4461638, 4552228, 4563790, 4584831, 4607992, 4884455, 4907501, 5045419, 5066844, 5150624, 5157161, 5190669, 5314703, 5337397, 5434807, 5440092, 5502665, 5523089, 5547122, 5566200, 5582936, 5634068, 5690330, 5776984, 5778441, 5818505, 5826687, 5827184, 5885735, 6010506, 6084254, 6131498, 6138324, 6250773, 6292801, 6306275, 6315242, 6331640, 6484374, 6502969, 6545970, 6666951, 6690905, 6763576, 6766086, 6895048, 6912227, 6929081, 6941390, 6978168, 7045672, 7085246, 7193307, 7197398, 7270237, 7276767, 7295790, 7375488, 7472098, 7687424, 7840758, 7880957, 7904499, 7948678, 7974126, 8015691, 8037685, 8112955, 8131380, 8140556, 8142384, 8220436, 8308817, 8331317, 22581970, 45809129, 48103779, 78212045, 79674901, 97299830, 110308649, 131744428, 136663461, 138485719, 139842794, 152061792, 152685704, 153070991, 156228213, 164884737, 174776199, 189346581, 193148547, 208582124, 223891881, 227308187, 237373798, 241214067, 242476929, 245495851, 260606593, 275202667, 285717038, 317009689, 322759532, 325369206, 339724742, 340122632, 345010859, 352375176, 355826263, 359695034, 366118516, 370008270, 382712922, 386379440, 401153345, 404986391, 426084981, 442843409, 473909474, 475192613, 492302667, 494747879, 506279889, 509813998, 537558350, 548423414, 548467404, 566383324, 574188786, 574792333, 591678147, 596558084, 597423476, 602432742, 603067874, 629552047, 630893263, 635249783, 644959276, 650710927, 664859367, 669433203, 684329599, 699991513, 714451929, 723556530, 739294558, 750895264, 757618344, 781123405, 796973385, 801637715, 804776709, 829003666, 829219068, 840167037, 854882202, 860066192, 864304878, 864808449, 867107161, 871871263, 880591851, 883020336, 883178082, 920223781, 936008673, 939417822, 956776353, 958281059, 962183717, 964059257, 967860573, 974322643, 974999286, 980009921, 1032949015, 1044249483, 1064892676, 1075628270, 1080848022, 1085571657, 1173635593, 1174809080, 1176744978, 1209783795, 1212074975, 1252323507, 1254757790, 1301450562, 1302240953, 1314501797, 1315121266, 1339304157, 1364304289, 1376260506, 1383883477, 1395158643, 1411117754, 1440755058, 1448365702, 1466814914, 1468433821, 1490105126, 1493912601, 1495600372, 1509536621, 1511014977, 1545693948, 1548924199, 1566583103, 1569747154, 1574097219, 1597784674, 1610710480, 1618324005, 1646105187, 1649417465, 1655649169, 1660619384, 1668826887, 1671093718, 1672456990, 1673477565, 1678638502, 1682302139, 1682515769, 1687920300, 1690062315, 1706031388, 1713660819, 1772170709, 1778416812, 1833443690, 1861312062, 1876004501, 1876358085, 1882435551, 1916050713, 1944906037, 1950207172, 1951593247, 1973638546, 1976288281, 1994977271, 2020053060, 2025281195, 2029716419, 2033980539, 2052482076, 2058251762, 2069273004, 2073978021, 2111013213, 2119886932, 2134609957, 2140349794, 2143934987]:
    # print(i,best_or_l(i,True))
    score = score + (len(l(i))-len(best_or_l(i,True)))
print("Score:",score)

with open("brute_serious_reverse.json","w") as outfile:
    outfile.write(json.dumps(best,sort_keys=True,indent=2))

3

अजगर 3, 34 39 बाइट्स बचाए गए

यह कार्यक्रम बस प्रत्येक संख्या की गणना करता है जो बाइनरी और यूनीरी ऑपरेटरों के सरल संयोजनों का उपयोग करके पहुंच सकता है, जो कि 4B पूर्णांकों में से 366k को कवर करता है, परीक्षण के दर्जनों मामलों में से एक जोड़े के लिए। फिर मैं उन परिणामों या तुच्छ समाधान का उत्पादन करता हूं। यह तकनीकी रूप से नियमों के खिलाफ है, क्योंकि यह निश्चित है कि कुछ मामलों के लिए एक बेहतर समाधान है, लेकिन मुझे विश्वास है कि कोई भी एक समाधान के साथ आने वाला नहीं है जो निश्चित रूप से उस नियम से गुजरता है।

इसके अलावा, मैं सिर्फ एक ही बार में सभी आउटपुट का उत्पादन कर रहा हूं, क्योंकि सेटअप समय के 30 सेकंड एक बार नहीं, 1000 बार होते हैं। टिप्पणी करने वाले सेक्शन रनटाइम को काफी बढ़ाते हैं जबकि स्कोर को मुश्किल से कम करते हैं।

#!/usr/bin/env python3
# -*- coding: cp437 -*-

import math
import gmpy
import json
import random

from seriously import chr_cp437

# MAX=2**31
MAX = 2**31

best = {}

def l(n,force_colon=False):
    if force_colon:
        return ':'+str(n)
    if n>=0 and n<10:
        return str(n)
    elif n<0 and n>-10:
        return str(-n)+chr_cp437(0xF1)
    return ':'+str(n)

def l2(n,m):
    if n<10 or best_or_l(n)[-1] in "0123456789":
        rep = l(n)+best_or_l(m)
    else:
        rep = best_or_l(n)+best_or_l(m,True)
    return rep

def cand(n,rep):
    # print(n,rep,len(rep),best[n] if n in best else "")
    if n!=int(n):
        return False
    n=int(n)
    if n<=MAX and len(rep)<len(l(n)) and (n not in best or len(rep)<len(best[n])):
        best[n] = rep
        return True
    return False

def best_or_l(n,force_colon=False):
    if n in best:
        return best[n]
    if -n in best and n>0:
        return best[-n]+chr_cp437(0xF1)
    return l(n,force_colon)

# digits
for i in range(0,10):
    best[i]=str(i)

# factorials
for i in range(4,13):
    cand(math.factorial(i),l(i)+'!')

# 10**i
for i in range(2,12):
    cand(10**i,l(i)+chr_cp437(0xD1))

# 2**i
for i in range(2,32):
    cand(2**i,best_or_l(i)+chr_cp437(0xD3))

# a choose b
for a in range(2,1000): # 466 is the highest a for MAX=2**24
    for b in range(2,int(a/2+1)):
        n = math.factorial(a)/(math.factorial(b)*math.factorial(a-b))
        if n>MAX:
            break
        cand(n,l2(b,a)+chr_cp437(0xDB))

# a P b
for a in range(2,1000): # 257 is the highest a for MAX=2**24
    for b in range(2,int(a/2+1)):
        n = math.factorial(a)/math.factorial(a-b)
        if n>MAX:
            break
        cand(n,l2(b,a)+chr_cp437(0xDC))

# fibonacci
def fib_formula(n):
    golden_ratio = (1 + math.sqrt(5)) / 2
    val = (golden_ratio**n - (1 - golden_ratio)**n) / math.sqrt(5)
    return int(round(val))
for i in range(3,47):
    cand(fib_formula(i),best_or_l(i)+'F')

# i^2 and ^4
for i in range(5,int(math.sqrt(MAX)+1)):
    cand(i*i,best_or_l(i)+chr_cp437(0xFD))

# a^b
for a in range(2,int(math.pow(MAX,1.0/3))+1):
    for b in range(3,int(math.log(MAX)/math.log(3))+1):
        n = a**b
        cand(n,l2(b,a)+chr_cp437(0xFC))

# exp(i)
for i in range(3,22):
    cand(int(math.ceil(math.exp(i))),best_or_l(i)+'eK')
    cand(int(math.floor(math.exp(i))),best_or_l(i)+'eL')

# primes
def primes():
    n = 2
    while True:
        yield n
        n = gmpy.next_prime(n)
n = 0
for p in primes():
    # print(p)
    if p>MAX/1000:
        break
    rep = best_or_l(n)+'P'
    cand(p,rep)
    n=n+1

# +1 +2 -1 -2 *2 /2 /4 
for key,value in sorted(best.items()):
    cand(key+1,value+'u')
    cand(key+2,value+chr_cp437(0xA9))
    cand(key-1,value+'D')
    cand(key-2,value+chr_cp437(0xAA))
    cand(key*2,value+chr_cp437(0xE7))
    if float(key)/2 == int(float(key)/2):
        cand(int((float(key)/2)),value+chr_cp437(0xAB))
    cand(int(math.floor(float(key)/2)),value+chr_cp437(0xAB)+'L')
    cand(int(math.ceil(float(key)/2)),value+chr_cp437(0xAB)+'K')
    if float(key)/4 == int(float(key)/4):
        cand(int((float(key)/4)),value+chr_cp437(0xAC))
    cand(int(math.floor(float(key)/4)),value+chr_cp437(0xAC)+'L')
    cand(int(math.ceil(float(key)/4)),value+chr_cp437(0xAC)+'L')

# bitwise invert
for key,value in sorted(best.items()):
    cand(~key,value+'~')

# arithmetic with small second operands
for key,value in sorted(best.items()):
    for op in ["+","-","/","/K","\\","*"]:
        for i in range(3,10):
            if op == "+":
                n = key+i
            elif op == "-":
                n = key-i
            elif op == "/":
                if i==4:
                    continue
                n = float(key)/i
                if int(n)!=n:
                    continue
                n = int(n)
            elif op == "/K":
                if i==4:
                    continue
                n = int(math.ceil(float(key)/i))
                if n == float(key)/i:
                    continue
            elif op == "\\":
                if i==4:
                    continue
                n = int(math.floor(float(key)/i))
                if n == float(key)/i:
                    continue
            elif op == "*":
                n = key*i
            rep = value+best_or_l(i)+op
            cand(n,rep)

# for key,value in sorted(best.items()):
#     print(key,value)

# def maybe(n,rep):
#     if len(rep)<len(best_or_l(n)):
#         return True
#     return False

# b=[]
# for k in sorted(best.keys()):
#     b.append(k)
#     if k>100000000:
#         break

# def search_for_better(n):
#     if n in best:
#         return best[n]
#     for i in b:
#         if n+i in best:
#             rep = best[n+i]+best[i]+'-'
#             if maybe(n,rep):
#                 return rep
#     for i in b:
#         if n-i in best:
#             rep = best[n-i]+best[i]+'+'
#             if maybe(n,rep):
#                 return rep
#     return l(n)

for key,value in sorted(best.items()):
    if random.random()<0.001:
        print(key,value)

score = 0
for i in [-2124910654, -2117700574, -2098186988, -2095671996, -2083075613, -2058271687, -2052250777, -2024215903, -2019485642, -2016095616, -2009838326, -2009173317, -2007673992, -2000014444, -1999825668, -1992515610, -1989566707, -1975506037, -1955473208, -1950731112, -1949886423, -1920624450, -1918465596, -1916287469, -1905036556, -1903956118, -1888944417, -1865221863, -1856600057, -1842797147, -1835637734, -1812631357, -1805740096, -1798015647, -1726688233, -1723609647, -1713776890, -1700307138, -1687644479, -1645515069, -1617635994, -1610444000, -1579053372, -1556891649, -1549652116, -1537732956, -1535180388, -1527162056, -1524851611, -1524658412, -1523244369, -1521379172, -1520191198, -1519035741, -1516978241, -1508892332, -1489938422, -1482102944, -1481823232, -1470621147, -1469145091, -1446844485, -1441790509, -1437843276, -1435359182, -1434186947, -1429816311, -1429393781, -1419752032, -1400387846, -1385152926, -1372620863, -1369257355, -1361933674, -1360480816, -1334846204, -1323741718, -1323660173, -1312800992, -1308824840, -1304658551, -1287829999, -1283767920, -1276288210, -1264275838, -1263965596, -1262866901, -1255421887, -1251428680, -1244825786, -1243200329, -1235305532, -1233977691, -1220537074, -1214100716, -1199414474, -1190725823, -1190401800, -1178717689, -1172378149, -1147869245, -1142875190, -1138538768, -1137864183, -1124917489, -1102987222, -1095920186, -1083001017, -1080902655, -1047122002, -1031842676, -1029877334, -1020849489, -1001684838, -998419619, -990915088, -985235989, -982515261, -979074894, -974195629, -973832940, -965324937, -944246431, -938387588, -933873331, -932692878, -928039285, -927947459, -914008773, -907981688, -906376330, -903502449, -898112547, -887444438, -862658502, -843628573, -822463032, -786051095, -776932426, -776033951, -752042328, -746532472, -743149468, -740225710, -734414418, -725435852, -708101516, -699674783, -694869277, -693246525, -690571518, -689249770, -688581912, -686864294, -681445866, -647992869, -641101583, -631409299, -624686189, -613079884, -593711206, -591688546, -591331185, -574790069, -573024823, -565387051, -565137163, -556338668, -556291492, -541411509, -538932064, -500479857, -482419890, -468050561, -424532545, -420534171, -408741873, -406973874, -387664799, -382084509, -367095703, -352332569, -352195997, -346430007, -324596389, -320119776, -306594578, -305952425, -283718911, -267302378, -243302738, -242955859, -232180029, -225394407, -217418127, -212286453, -208344820, -191300139, -186177744, -175765723, -161763935, -157025501, -140389149, -132298608, -126175769, -70566352, -68748576, -53985905, -52674668, -50228620, -39678495, -19825663, -8349922, -8186722, -8125700, -8073135, -8043230, -7994382, -7874433, -7863624, -7784916, -7782477, -7696343, -7607278, -7531250, -7388060, -7368780, -7367625, -7353084, -7334489, -7281141, -7267149, -7140057, -7119066, -7010389, -6992089, -6975258, -6863360, -6784772, -6741079, -6585985, -6550401, -6520011, -6495144, -6459702, -6294273, -6178342, -6169344, -6139663, -6090928, -6022637, -5992707, -5971334, -5925304, -5880940, -5873707, -5807953, -5703992, -5692895, -5535131, -5488812, -5468330, -5404148, -5290247, -5274221, -5264144, -5234715, -5224048, -5179837, -5084014, -5043990, -5028537, -5011679, -4998333, -4922901, -4880159, -4874060, -4787390, -4749096, -4736217, -4502308, -4480611, -4424319, -4363262, -4349743, -4290050, -4240069, -4239657, -4174072, -4093051, -4045363, -4037689, -4033352, -3839265, -3766343, -3716899, -3680075, -3679053, -3581776, -3539227, -3461158, -3282526, -3205947, -3183427, -3169708, -3166430, -3089822, -3061531, -2947574, -2930733, -2919246, -2872882, -2830770, -2739228, -2713826, -2634018, -2613990, -2525529, -2439507, -2432921, -2376201, -2335005, -2307524, -2265548, -2176176, -2123133, -2108773, -2105934, -2075032, -2073940, -2045837, -2045648, -1978182, -1945769, -1935486, -1881608, -1654650, -1602520, -1506746, -1505294, -1475309, -1457605, -1327259, -1312217, -1178723, -1027439, -880781, -833776, -666675, -643098, -593446, -468772, -450369, -443225, -418164, -402004, -319964, -307400, -279414, -190199, -176644, -66862, -32745, -32686, -32352, -32261, -32035, -31928, -31414, -31308, -30925, -30411, -29503, -29182, -28573, -28500, -28093, -27743, -27716, -27351, -27201, -26834, -25946, -25019, -24469, -24341, -24292, -24151, -23732, -22769, -22242, -22002, -20863, -20762, -20644, -20189, -20009, -19142, -19036, -18980, -18616, -18196, -18123, -17942, -17915, -17601, -17494, -16669, -16417, -16317, -15051, -14796, -14742, -14600, -14443, -14159, -14046, -13860, -13804, -13745, -13634, -13498, -13497, -12688, -12471, -12222, -11993, -11467, -11332, -10783, -10250, -10114, -10089, -9930, -9434, -9336, -9128, -9109, -8508, -8460, -8198, -8045, -7850, -7342, -7229, -6762, -6302, -6245, -6171, -5957, -5842, -4906, -4904, -4630, -4613, -4567, -4427, -4091, -4084, -3756, -3665, -3367, -3186, -2922, -2372, -2331, -1936, -1683, -1350, -1002, -719, -152, -128, -127, -124, -122, -121, -119, -116, -113, -112, -111, -107, -104, -102, -101, -100, -95, -94, -91, -90, -87, -81, -80, -79, -78, -73, -72, -69, -68, -66, -65, -63, -57, -54, -52, -51, -48, -47, -46, -45, -43, -41, -37, -33, -31, -30, -27, -25, -21, -18, -15, -12, -8, -1, 0, 1, 3, 4, 5, 6, 11, 14, 17, 23, 25, 26, 27, 28, 29, 31, 32, 39, 41, 46, 49, 51, 52, 56, 58, 61, 64, 66, 67, 70, 74, 79, 80, 86, 88, 89, 92, 93, 99, 102, 104, 109, 113, 117, 120, 122, 123, 127, 695, 912, 1792, 2857, 3150, 3184, 4060, 4626, 5671, 6412, 6827, 7999, 8017, 8646, 8798, 9703, 9837, 10049, 10442, 10912, 11400, 11430, 11436, 11551, 11937, 12480, 13258, 13469, 13689, 13963, 13982, 14019, 14152, 14259, 14346, 15416, 15613, 15954, 16241, 16814, 16844, 17564, 17702, 17751, 18537, 18763, 19890, 21216, 22238, 22548, 23243, 23383, 23386, 23407, 23940, 24076, 24796, 24870, 24898, 24967, 25139, 25176, 25699, 26167, 26536, 26614, 27008, 27087, 27142, 27356, 27458, 27800, 27827, 27924, 28595, 29053, 29229, 29884, 29900, 30460, 30556, 30701, 30815, 30995, 31613, 31761, 31772, 32099, 32308, 32674, 75627, 80472, 103073, 110477, 115718, 172418, 212268, 242652, 396135, 442591, 467087, 496849, 675960, 759343, 846297, 881562, 1003458, 1153900, 1156733, 1164679, 1208265, 1318372, 1363958, 1411655, 1522329, 1559609, 1677118, 1693658, 1703597, 1811223, 1831642, 1838628, 1884144, 1931545, 2085504, 2168156, 2170263, 2239585, 2308894, 2329235, 2364957, 2432335, 2435551, 2596936, 2684907, 2691011, 2705195, 2738057, 2851897, 2925289, 2995414, 3051534, 3216094, 3267022, 3271559, 3338856, 3440797, 3638325, 3651369, 3718696, 3724814, 3811069, 3854697, 3866969, 3893228, 3963455, 3984546, 4098376, 4100957, 4128113, 4200719, 4256344, 4286332, 4306356, 4316314, 4438803, 4458063, 4461638, 4552228, 4563790, 4584831, 4607992, 4884455, 4907501, 5045419, 5066844, 5150624, 5157161, 5190669, 5314703, 5337397, 5434807, 5440092, 5502665, 5523089, 5547122, 5566200, 5582936, 5634068, 5690330, 5776984, 5778441, 5818505, 5826687, 5827184, 5885735, 6010506, 6084254, 6131498, 6138324, 6250773, 6292801, 6306275, 6315242, 6331640, 6484374, 6502969, 6545970, 6666951, 6690905, 6763576, 6766086, 6895048, 6912227, 6929081, 6941390, 6978168, 7045672, 7085246, 7193307, 7197398, 7270237, 7276767, 7295790, 7375488, 7472098, 7687424, 7840758, 7880957, 7904499, 7948678, 7974126, 8015691, 8037685, 8112955, 8131380, 8140556, 8142384, 8220436, 8308817, 8331317, 22581970, 45809129, 48103779, 78212045, 79674901, 97299830, 110308649, 131744428, 136663461, 138485719, 139842794, 152061792, 152685704, 153070991, 156228213, 164884737, 174776199, 189346581, 193148547, 208582124, 223891881, 227308187, 237373798, 241214067, 242476929, 245495851, 260606593, 275202667, 285717038, 317009689, 322759532, 325369206, 339724742, 340122632, 345010859, 352375176, 355826263, 359695034, 366118516, 370008270, 382712922, 386379440, 401153345, 404986391, 426084981, 442843409, 473909474, 475192613, 492302667, 494747879, 506279889, 509813998, 537558350, 548423414, 548467404, 566383324, 574188786, 574792333, 591678147, 596558084, 597423476, 602432742, 603067874, 629552047, 630893263, 635249783, 644959276, 650710927, 664859367, 669433203, 684329599, 699991513, 714451929, 723556530, 739294558, 750895264, 757618344, 781123405, 796973385, 801637715, 804776709, 829003666, 829219068, 840167037, 854882202, 860066192, 864304878, 864808449, 867107161, 871871263, 880591851, 883020336, 883178082, 920223781, 936008673, 939417822, 956776353, 958281059, 962183717, 964059257, 967860573, 974322643, 974999286, 980009921, 1032949015, 1044249483, 1064892676, 1075628270, 1080848022, 1085571657, 1173635593, 1174809080, 1176744978, 1209783795, 1212074975, 1252323507, 1254757790, 1301450562, 1302240953, 1314501797, 1315121266, 1339304157, 1364304289, 1376260506, 1383883477, 1395158643, 1411117754, 1440755058, 1448365702, 1466814914, 1468433821, 1490105126, 1493912601, 1495600372, 1509536621, 1511014977, 1545693948, 1548924199, 1566583103, 1569747154, 1574097219, 1597784674, 1610710480, 1618324005, 1646105187, 1649417465, 1655649169, 1660619384, 1668826887, 1671093718, 1672456990, 1673477565, 1678638502, 1682302139, 1682515769, 1687920300, 1690062315, 1706031388, 1713660819, 1772170709, 1778416812, 1833443690, 1861312062, 1876004501, 1876358085, 1882435551, 1916050713, 1944906037, 1950207172, 1951593247, 1973638546, 1976288281, 1994977271, 2020053060, 2025281195, 2029716419, 2033980539, 2052482076, 2058251762, 2069273004, 2073978021, 2111013213, 2119886932, 2134609957, 2140349794, 2143934987]:
    print(i)
    print(best_or_l(i,True))
    score = score + (len(l(i))-len(best_or_l(i,True)))
print("Score:",score)

# print(len(best))

with open("aim.json","w") as outfile:
    outfile.write(json.dumps(best,sort_keys=True,indent=2))

यहाँ वास्तव में इस एल्गोरिथम द्वारा पाए जाने वाले कार्यक्रमों के प्रकारों का एक यादृच्छिक नमूना है:

15875 49█²D
178085 :422²u
6195119 :2489²¬
11276166 :3358²⌐
14516098 :3810²¬
32924643 :5738²D
35003345 :8367²½K
66438802 :8151²u
95664294 3:363ⁿτ
100915813 3:847۪
111894084 :10578²
219662043 :14821²⌐
220849321 :14861²
236390625 :15375²
282710596 :16814²
296511180 :34439²¼L
375584401 :19380²u
460188303 :21452²D
465157056 :43135²¼L
509991890 :22583²u
510963420 :45209²¼L
606981768 :24637²D
659407868 8FeK½K
697212482 :18671²τ
805764994 :28386²¬
852225612 :41285²½L
941078331 :30677²⌐
1034715540 :45491²½L
1193771602 :34551²u
1326125054 :36416²¬
2030403600 :45060²
2078904023 :45595²¬

1
इस चुनौती में @ केविनलाउ-केकेनी स्कोर कुल उत्पादन का हजार है, वास्तव में कार्यक्रम, पायथन कार्यक्रम के आकार का नहीं
स्पेर

मुझे यह तरीका पसंद है। मैं समय के प्रतिबंध के साथ थोड़ा और अधिक लचीला होने के लिए तैयार हूं और यह अवश्य ही बेहतर-से-तुच्छ नियम है यदि यह अधिक दिलचस्प समाधानों की अनुमति देता है - मैं मुख्य रूप से सदियों से चलने वाले अनूठे पाशविक बल समाधानों से बचना चाहता था। "प्रीपेंड ए:" का तुच्छ समाधान, जो अकल्पनीय है और चुनौती की भावना के खिलाफ जाता है।
मेगो

मैंने आवश्यकताओं को संशोधित किया है ताकि समाधान केवल कम से कम तुच्छ समाधान करने के लिए हो, बल्कि यदि संभव हो तो बेहतर हो, और समय सीमा को प्रति सेकंड 30 सेकंड तक बढ़ाया जाए। आपका समाधान अब मान्य है, और आप आराम की आवश्यकताओं के साथ कुछ अतिरिक्त सुधार करने में सक्षम हो सकते हैं।
मेगो
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.