12
\$\begingroup\$

As a spin-off to my challenge over at Puzzling, your goal is to output 2016.

Rules:

  • You must include the numbers 10 9 8 7 6 5 4 3 2 1 in that order. They can be used as individual integers or concatenated together (like 1098), but the 10 may not be separated into 1 and 0 - no character(s) may be present between the digits. Note that, in some languages, 10 may not actually represent the integer literal 10, which is acceptable.
  • Your code must not contain any other numbers or pre-defined number variables or constants (so T in Pyth is not allowed, since it is a numeric constant).
  • You must calculate 2016 using numerics. Simply outputting 2016 without performing any operations on the required numbers (for example, by decoding an encoded string consisting of only alphabetic characters) is not allowed. Outputting 2016 in pieces (such as 20, then 16) is also not allowed; you must have a single output consisting of the numeric value 2016.
  • The valid answer with the fewest bytes wins.
\$\endgroup\$
  • 3
    \$\begingroup\$ @nicael I'm pretty sure solving the puzzle has been done. We've had several of these "insert operators to solve an equation" challenges, but they are exceptional hard to search for. \$\endgroup\$ – Martin Ender Jan 6 '16 at 13:40
  • 1
    \$\begingroup\$ The previous revision (2) was more interesting actually. The new is just printing the string, the calculation was already made in your puzzling question... \$\endgroup\$ – nicael Jan 6 '16 at 14:19
  • 1
    \$\begingroup\$ Just a few questions based on what I can see on the current question: 1) Can we calculate 20 and 16 and print them one after the other or does the calculated number need to be 2016 before printing? 2) Are functions allowed? 3) Is concatenation of digits allowed? e.g. 1098 (I'm assuming yes by previous comments, but just to confirm) 4) Does "calculate 2016 using integers" mean that we can never have floats anywhere in an intermediate step? e.g. can I square root a number and round down? \$\endgroup\$ – Sp3000 Jan 6 '16 at 23:17
  • 1
    \$\begingroup\$ 5) What happens if I have a language where "10" is not treated as the number ten, but rather a one followed by a zero and there was no way around it? Is such a language disqualified? (example language: Befunge) 6) Can we use a predefined number variable in place of 10, e.g. T987654321? \$\endgroup\$ – Sp3000 Jan 6 '16 at 23:19
  • \$\begingroup\$ @Sp3000 1 No. 2 No. 3 Yes. 4 Floats are OK as long as you don't break any other rules. 5 10 must be included so you would need to handle that somehow. 6 As long as 10 appears before T. \$\endgroup\$ – rybo111 Jan 7 '16 at 0:15

22 Answers 22

22
\$\begingroup\$

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.
\$\endgroup\$
8
\$\begingroup\$

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 < } { >
 . . . $ _ 5 _ 4
/ * ! @ . . . . .
 / } 3 . . " 2 \
  / = " * = } <
   * . . . $ 1
    > " * " /

Explanation coming soon;

\$\endgroup\$
  • 5
    \$\begingroup\$ "Explanation coming soon;" I think we have a different understanding of 'soon'. ;P \$\endgroup\$ – Kevin Cruijssen Apr 5 '17 at 14:03
  • 1
    \$\begingroup\$ @KevinCruijssen Whoops, I completely forgot about this. ... And now I don't understand how it works anymore. Great. \$\endgroup\$ – Blue Apr 28 '17 at 22:15
5
\$\begingroup\$

Pyth, 16 bytes

+/109876 54-3 21

Does integer division, then adds (3-21).

Try it here.

\$\endgroup\$
4
\$\begingroup\$

TI-BASIC, 17 15 bytes

int(109876/54-√(321

This uses @nicael's method.

17 bytes:

10+9*8-7+654*3-21

This solution from Puzzling can be directly translated into TI-BASIC.

\$\endgroup\$
  • 1
    \$\begingroup\$ Also valid in Japt, and probably some others. \$\endgroup\$ – ETHproductions Jan 6 '16 at 19:02
  • 1
    \$\begingroup\$ Also works in PowerShell, and Mathematica (Wolfram), and I would imagine many, many others. And probably works in dozens more with trivial modifications. \$\endgroup\$ – AdmBorkBork Jan 6 '16 at 19:19
  • \$\begingroup\$ A lovely polyglot solution \$\endgroup\$ – TanMath Jan 6 '16 at 19:36
  • \$\begingroup\$ If you want to take the other languages, I'll delete my community wiki one. \$\endgroup\$ – Addison Crump Jan 6 '16 at 19:39
3
\$\begingroup\$

Japt, 17 16 bytes

Â(109876/54-321q

I hate this 17. Probably will find another solution. YAYZ.

Explanation:

  • 321q is a square root of 321.
  • ~~ floors the number.

Try it online!

\$\endgroup\$
  • \$\begingroup\$ Â == ~~ :-) \$\endgroup\$ – ETHproductions Jan 6 '16 at 22:35
  • \$\begingroup\$ 109876/54-321¬f is 15 :-D \$\endgroup\$ – ETHproductions Jan 6 '16 at 22:36
  • \$\begingroup\$ @Eth but f doesn't work, no? \$\endgroup\$ – nicael Jan 6 '16 at 22:37
  • \$\begingroup\$ It should be fixed. But the interpreter is down for maintenance right now, I'll get it back up momentarily. \$\endgroup\$ – ETHproductions Jan 6 '16 at 22:38
  • \$\begingroup\$ 109876/54-321q)f now works. The other suggestion doesn't. \$\endgroup\$ – ETHproductions Jan 6 '16 at 22:47
3
\$\begingroup\$

Matlab / Octave, 23 bytes

(10-9+8-7)^(6-5+4)*3*21

Try it online

\$\endgroup\$
3
\$\begingroup\$

bc, 14

109876/54+3-21

Nothing exciting here - borrows from other answers.

\$\endgroup\$
  • 1
    \$\begingroup\$ The dc equivalent 109876 54/3+21-p scores 16, but doesn't warrant an answer of its own. \$\endgroup\$ – Toby Speight Jan 8 '16 at 8:55
2
\$\begingroup\$

Haskell, 31 bytes

[10,9*8*7+const 6 5..]!!4+3*2*1

Not the shortest, 10+9*8-7+654*3-21 like seen in other answers works in Haskell too, but something different.

This builds a list starting with 10 and 9*8*7+6 = 510, so the offset is 500 for the following elements. The whole list is [10,510,1010,1510,2010,2510 ...]. We pick the 4th element (index 0-based), i.e. 2010 and add 3*2*1 = 6. Voilà.

I use const 6 5 = 6 to get rid of the 5 which is not needed.

\$\endgroup\$
2
\$\begingroup\$

Python 2, 20 bytes

print 109876/54+3-21

Again, that same boring 2016.(740). Makes use of the fact that if you don't have a decimal number in your expression it returns an integer.

\$\endgroup\$
1
\$\begingroup\$

><> (fish), 18 bytes

10987**r65r4*n;321

explaination:

multiplies 9 8 and 7 together to get 504, reverses the stack and reverses it again right before the 4 is added, then multiplies 504 and 4 to get 2016. Then prints the number and ends the program before the last 3 numbers (i could do it after too with no difference, if that matters rules-wise).

\$\endgroup\$
1
\$\begingroup\$

Math++, 17 bytes

_(109876/54)+3-21

Actually, this prints 2016.0. But there's really no way to print the exact string 2016 in this language.

The 17-byte TI-BASIC solution would also work here.

\$\endgroup\$
1
\$\begingroup\$

Polyglot, 17 Bytes

10+9*8-7+654*3-21

This code, first used in Thomas Kwa's TI-BASIC answer, also works in:

  • AppleScript (full program)
  • bc (full program)
  • Math++ (expression or full program)
  • Mathematica (function, therefore not valid)
  • Powershell (full program)
  • Japt (full program)
  • JavaScript (console input, therefore not valid) Needs second verification
  • Perl 5 (function, therefore not valid). Needs second verification
  • Haskell (function, therefore not valid)
  • Python REPL (expression, so REPL environment is needed to get the output)
\$\endgroup\$
  • 1
    \$\begingroup\$ And, what's the point? \$\endgroup\$ – nicael Jan 6 '16 at 19:34
  • \$\begingroup\$ @nicael I'm ---going--- am planning (unless Thomas Kwa wishes to add the other answers to his as well) to add all of the answers that involve this answer (except TI-BASIC) that I can find. Marked as Community so that others can contribute. \$\endgroup\$ – Addison Crump Jan 6 '16 at 19:38
  • 1
    \$\begingroup\$ Why the "function, therefore not valid" remarks? Functions are allowed by default. \$\endgroup\$ – nimi Jan 6 '16 at 21:54
  • 5
    \$\begingroup\$ I don't know about the other languages, but 10+9*8-7+654*3-21 is neither a JavaScript nor a Perl function. \$\endgroup\$ – Dennis Jan 6 '16 at 21:56
  • 1
    \$\begingroup\$ @Sp3000: Oh these invalidating rule changes ... \$\endgroup\$ – nimi Jan 7 '16 at 0:50
1
\$\begingroup\$

𝔼𝕊𝕄𝕚𝕟 2, 15 chars / 17 bytes

109876/54+3-21⍜

Try it here (Firefox only).

Translates to round(109876/54+3-21).

Thanks to @Dennis for saving 2 bytes!

\$\endgroup\$
1
\$\begingroup\$

Java 7, 31 bytes

int c(){return 109876/54+3-21;}

Boring port from other answers, of which I believe @Dennis' Jelly answer was the first.

\$\endgroup\$
1
\$\begingroup\$

PHP, 27 bytes

<?=~~(109876/54+3-21);

(22 bytes) was too boring,

so I used 10 to 9 as separate numbers:

<?=10*(9-8+7-6),5+4-3+2<<1;

other solutions, mostly with small cheats:

30: <?=10**(9+8-7-6)/5+4*3+(2<<1);
30: <?=10*trim(9*8,7),6+5+4+3-2*1;
29: <?=10*trim(9*8,76),5*4-3-2+1;
31: <?=10*trim(9*8,765),4+(3*2<<1);
31: <?=10*trim(9*8,765),4*3+(2<<1);
32: <?=ceil(1098*76/54)+321+ord(~j);
33: <?=(10<<9)/876*543/M_PI*2-M_E&~1;
\$\endgroup\$
0
\$\begingroup\$

Milky Way 1.6.5, 28 25 bytes

10+9*(8)7;^*6*5/4*3/2*A!1

Explanation

10+9*                      ` perform 10*9 (leaves 90 at TOS)
     (8)7;^*               ` get rid of 8 and multiply the TOS by 7
            6*5/4*3/2*A    ` perform TOS*6/5*4/3*2 (leaves 2016 at TOS)
                       !   ` output the TOS
                        1  ` push 1 to the stack
\$\endgroup\$
0
\$\begingroup\$

BotEngine, 42 39 36 13x2=26

v109876543210
>ee   e@  eRP
\$\endgroup\$
0
\$\begingroup\$

05AB1E, 15 bytes

109876 54÷3+21-

Try it online!

Port of Dennis' answer.

\$\endgroup\$
0
\$\begingroup\$

Forth, 22 bytes

Same calculation seen in other answers.

109876 54 / 3 + 21 - .

Try it online

\$\endgroup\$
0
\$\begingroup\$

C 37 bytes

main(){printf("%d",109876/54+3-21);}

Same theme as many present.

\$\endgroup\$
0
\$\begingroup\$

VBA, 15 bytes

?109876\54+3-21

(calculation unashamedly stolen from Dennis)

\$\endgroup\$
0
\$\begingroup\$

JavaScript (ES6), 21 bytes

f=

_=>~~(109876/54+3-21)

console.log(f())

If the "countdown" went to 0, it could be done in 19 bytes.

f=
_=>109876/54+3-21|0
console.log(f())

And, seeing as it's 2017 now, that can also be done in 21 bytes:

f=
_=>-~(109876/54+3-21)
console.log(f());

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.