# Tag Info

28

Python 2, 171 156 bytes lambda a:max(e(a))-min(e(a)) u=')%s(' def e(a,t=u): try:b=[eval(a)] except:b=[] return sum([e('(%s)'%a.replace(o,t%o),u%t)for o in"+-*/%"if' '+o in a],b) Try it online! How it works We surround each operator with a different number of outward-facing pairs of parentheses to simulate different precedences (in all possible ways), ...

22

Jelly, 17 15 14 bytes 109876:54+3_21 Try it online! How it works 109876:54+3_21 109876 Initialize the left argument as 109876. :54 Perform integer division by 54, yielding 2034. +3 Add 3, yielding 2037. _21 Subtract 21, yielding 2016.

17

Python 2, 74 70 bytes f=lambda n:min([n]+[f(j)+min(n%j*n+f(n/j),f(n-j))for j in range(2,n)]) Try it online! Alternate version, 59 bytes (unverified) f=lambda n:min([n]+[f(j)+f(n/j)+f(n%j)for j in range(2,n)]) This works at least up to n = 1,000,000, but I have yet to prove that it works for all positive n. Try it online!

16

Retina, 58 bytes [-+] $&1 \B((\+1)|(-1))*$._$*1$#3$*1$#2$*_$& +1_ 1+ $.& Try it online! Alternative solution at the same byte count: ((\+)|(-))*$._$*1$#3$*1$#2$*_$& +1_ ([+-])1* $+1 1+$.& Try it online! Explanation The basic idea is to turn all the +s and -s into simple +1 and -1 operations and then to prepend a sufficiently ...

10

JavaScript (ES6), 153 176 bytes EDIT: In non-strict mode, JS interprets 0-prefixed numerical expressions as octal (e.g. 017 is parsed as 15 in decimal). This is a fixed version that supports leading zeros. let f = s=>[...Array(3**(l=s.length,l-1))].map((_,n)=>m=eval((x=s.replace(/./g,(c,i)=>c+['','+','-'][o=(n/3**i|0)%3,j-=!o,o],j=l)).replace(/\...

10

Jelly, 16 14 bytes Thanks Dennis for saving 2 bytes! ÆḌḊ,Ṗß€€+U$FṂo Try it online! Logic explanation Given a number n: If it's 1, the answer is 1. Otherwise: The representation is either a + b or a × b, where a and b are expressions. Consider all possible values of a and b: If the representation is a + b, then a and b are in range [1 .. n-1]. If the ... 9 85, ~2400 bytes I'm a bit sad this is a code golf challenge, as I feel that all my previous efforts have been rather useless now that I'll post this: 0 = ((2*0)^15) 1 = ((2^0)^15) 2 = (2-(0^15)) 3 = (20*.15) 4 = (20*(1/5)) 5 = (20-15) 6 = ((.20+1)*5) 7 = ((20*.1)+5) 8 = (2*((0-1)+5)) 9 = ((.20/.1~)*5) 10 = (20/(1/.5)) 11 = ((((2-0)+1))!+... 9 Hexagony, 888 bytes Okay, first some ground rules for Hexagony, in case anyone wants to beat this: I'm interpreting "snippet" as a linear piece of code that can be dumped into any sufficiently large program, provided the current and adjacent memory edges are zero. The snippet has to be entered from the left and exited from the right. I'd be able to save ... 8 Python 155 bytes ï»¿h={4:'4',24:'4!',6:'â4',.4:'.4',1:'âû4',4/9.:'.4~'} f={} def g(r,s='24',y='4!'):f[eval(s)]=y;[g(r-1,s+o+k,y+o+h[k])for k in h for o in'/*-+'if r] g(3) The first three bytes (\xEF\xBB\xBF) are the UTF-8 byte order mark, although the file should be saved in an ANSI format. The û and â will be interpretted as √ and Γ respectively in ... 8 Hexagony, 61 bytes Not gonna win, but I just wanted to do a challenge in Hexagony. This uses a different method than other answers (much worse). It takes some factors of 2016 (2,3,6,7,8) and multiplies them all together. Minified: \109.8/7}_=\"6<}{>...$_5_4/*!@...../}3.."2\/="*=}<*...$1>"*"/ Unminified: \ 1 0 9 . 8 / 7 } _ = \ " 6 &... 8 J, 1041 ... 838 bytes 981 961 952 860 859 I got a little lazy to the end, but it should be more fixed than less. I don't think I'll ever overtake Hexagony, but you never know! beating hexagony! Saved 9 bytes thanks to Zgarb! and so much more to Lynn! 20=16 *2016 2[016 2+01[6 20-16 p:2[016 201]6 2+0-1-6 -:20]16 2+01+6 -:20[16 p:20-16 +/2$01]6 <:20-1]6 ...

8

Python 2, 76 bytes lambda e:sum([[len(e+s)-2*s.count('+')]+*len(s)for s in e.split('=')],[]) Try it online!

8

Haskell, 42 bytes f n=[l|l<-mapM(\i->[i,-i])[1..n],0==sum l] Try it online!

8

05AB1E, 25 24 bytes 9Ýœ"+-*m"9ãðδšδ.ιJ˜.Δ.VQ Brute-force approach, so obviously extremely slow. Outputs in reverse Polish notation, with the characters +-*m for addition, subtraction, multiplication, and exponentiation respectively. Division isn't necessary for the $[0,100000]$ range we have to support. Try it online with additional (first) ...

7

JavaScript, 1021 bytes Fixed and saved two bytes thanks to Charlie Wynn and ETHProductions. 201&6 -~!2016 2%016 201%6 20%16 2^0^1^6 2*0*1+6 2|0|1|6 2*01+6 2-~01+6 ~2+016 ~2+016 2^016 20-1-6 2|016 20+1-6 20&16 2-~016 2.0+16 20^1+6 20|16 -~20|16 20*1|6 20|1|6 -2*~01*6 20-1+6 20+1*6 20+1+6 2*016 -~(2*016) 2*-~016 ~-(2.0*16) 2.0*16 -~(2.0*16) 2.0*-~16 ~-...

7

JavaScript (ES7), 836 bytes Everything should work in any browser except 81, 88, and 97, which use the new ** operator. Mostly everything here was done by hand. I've been working on a brute-forcer to improve anything that can be improved. Currently it has saved 103 bytes on various items. 0: 201&6 1: 2-01%6 2: 2%016 3: 201%6 4: 20%16 5: ...

7

Jelly, 686 bytes 20=16 20>16 2+0%16 201%6 20%16 20%16‘ 201a6 20>1+6 20%16Ḥ 2016DS 20Ho16 2016BL 20:1.6 20_1_6 20×1_6 20+1_6 20&16 20:+16 2+0+16 20+1^6 20|16 20|16‘ 20|16‘‘ 20%16!’ 20%16! 20²:16 20H+16 20+1+6 20×1_6Ḥ 20×1_6Ḥ‘ 20+1_6Ḥ 2016&½’ 2016&½ 201:6 201:6‘ 20Cạ16 20+16 20+16‘ 20+1^6Ḥ 20|16Ḥ’ 20|16Ḥ 20|16Ḥ‘ 20|16‘Ḥ 2016½Ḟ’ 2016½Ḟ 2016½Ċ ...

7

Jelly, 126 bytes "Operator Precedence? Parentheses? Pah, who needs that?" - challenges of using Jelly for an operator precedence challenge. ⁾[]i$€Ḥæ%3+\¬œp¹Ḋ€ ÇµḟØDO%9µÐṀṪɓœṣ⁹,ṚÑj@¥/ ÇµVṾµ1ĿFḟØDḟ”-Lµ?ÐL 5Ḷx@€“]“[”ż⁸j/€,@y³Fɓ³i@€Ṁ’x@“[“]”jÇ “+_×:%”Œ!Ç€µṾL_L’ỊµÐfV€ṢIS Try it online! Input is taken as a string, e.g. "1+2_3×4:5%6". Note multiplication uses "×... 7 Jelly, 9 bytes 1,-ṗ×RSÐḟ Try it online! Exp 1,-ṗ×RSÐḟ Main link. Input = n. Assume n=2. 1,- Literal list [1, -1]. ṗ Cartesian power n. Get [[1, 1], [1, -1], [-1, 1], [-1, -1]] ×R Multiply (each list) by Range 1..n. Ðḟ ḟilter out lists with truthy (nonzero) S Sum. Jelly, 9 bytes Jonathan Allan's suggestion, ... 7 Python 3, 210 bytes · 100 + 59045 digits = 80045 def f(n,d): m={d:d}, while{n}-{*m}:m={z:(p[x],o,q[y])for p,q in zip(m,m[::-1])for x in p for y in q for z,o in zip([x+y,x-y,x*y,y<9and x**y,x%y<1and x//y,int(f"{x}{y}")],"+-*^/|")if z>0},*m return m[n] Try it online! Scoring Scoring goes much faster using this modified version that solves ... 6 GolfScript (129 chars*) [4.2'√4'24'4!'6'Γ4'1'Γ√4'120'ΓΓ4']2/:F{.F=[[44.]]*\{{+{'+*-'1/{:^;.[~@[\]{'()'1/*}%^*@@^~\]\}/}:|~2/~\+|;}+F/}%+}3*\{\0==}+?1= Running time is on the order of 4 minutes on my PC. A moderate speed-up can be obtained at the cost of two characters by adding a uniqueness operation .& immediately after the %+. I use pre-coded ... 6 Python 3, 424 420 369 363 bytes import time as t r=range x=len d=list(t.strftime('%m%d%y')) o=([[x,x+'(',x+')']for x in ['']+"+ - == * / **".split()]) n=[] for l in o: n=l+n o=n for p in r(x(o)**(x(d)-1)): e='' for i in r(x(d)-1): e+=str(d[i])+o[(p//(x(o)**i))%x(o)] e+=str(d[-1]) try: if eval(e)and e.find('=')!=-... 6 Dyalog APL (This is a joke, please don't submit), 25,957 bytes. 2016⊢≢⍬ 2016⊢(⊢+≢)≢⍬ 2016⊢(⊢+≢)(⊢+≢)≢⍬ ... Yeah, this is a joke entry, we need an APL solution, even if it's completely horrible. Works by incrementing ≢⍬ (0) n times. I don't want to give any secrets away from my actual submission. Obviously could be golfed much more. 6 Python 2, 199 179 178 172 162 158 156 152 151 bytes Way too long, but the solution was easy to create. from itertools import* i=input() k='%s' s=k+k.join(i)+k for p in product(*[range(1,65537)]*-~len(i)): if eval((s%p).replace('=','==')):print s%p;break Try it online This will try every possibility until it finds a solution. The program is extremely ... 6 Python 2, 235 234 233 226 bytes -1 byte (and a fix) thanks to Anders Kaseorg! -7 bytes thanks to Step Hen! from itertools import* def f(e,a=()): for o in permutations("+-*/%"): l=e[:] for c in o: for i in range(len(l),0,-1): if l[i-1]==c:l[i-2:i+1]=["("+l[i-2]+l[i-1]+l[i]+")"] try:a+=eval(*l), except:0 print max(a)-min(a) ... 6 JavaScript (Node.js), Score: 87900 ... 83274 82574 229 bytes x 100 + 59674 digits Takes input as (d)(n). Returns a string. Uses | for concatenation. d=>n=>[0,v=[d],F={[d]:d},s={[d]:0}].map(_=>v.map(x=>v.map(y=>[x+y,x-y,x*y,x/y,x**y,[x]+y].map((z,o)=>z<0|z>1e4||z%1?0:(!F[z]&&V.push(+z))|(S=s[x]-~s[y])<s[z]?F[s[z]=S,z]=(${...

5

Pyth, 16 bytes +/109876 54-3 21 Does integer division, then adds (3-21). Try it here.

5

Javascript (E6) 215 (315 - 2*50 bonus) 252 Edit Simplified. Correct bug of 0 missing Defined as a function, then counting 10 more byte for output using alert() Important Really this one is not valid according to the rules, because javascript can not handle big numbers. For instance with parameters 2,5 it can't find 2^2^2^2^2 (ie 2^65536). A number this ...

5

C++17, score .0086 This program has non-deterministic penalty score due to thread races, so I'm declaring based on an average of three runs, each of which handled the test suite in under a minute: score 0.000071 for 14(11*13) = 14143 score 0.000019 for (696699+66)*69 = 48076785 score 0.000069 for 333333+333333333+33333 = 333699999 score 0.000975 for 5(1((((...

5

Python 2, 120 119 bytes -1 byte thanks to mbomb007 a=['1'+(n and('1'.join(n)+'1'))for n in input().split('=')] print'='.join(max(map(eval,a))-eval(c)+1+c[1:]for c in a) Try it online! or Verify all test cases First I insert 1 in every position, to check the highest value, then add it as offset on every equation. This work because you can't add ...

Only top voted, non community-wiki answers of a minimum length are eligible