10 9 8 7 6 5 4 3 2 1... Print 2016

12

2

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.

rybo111

Posted 2016-01-06T13:19:29.257

Reputation: 4 071

3@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. – Martin Ender – 2016-01-06T13:40:50.770

1The previous revision (2) was more interesting actually. The new is just printing the string, the calculation was already made in your puzzling question... – nicael – 2016-01-06T14:19:24.343

1Just 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? – Sp3000 – 2016-01-06T23:17:35.897

1 start="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?
  • < – Sp3000 – 2016-01-06T23:19:52.393

    @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. – rybo111 – 2016-01-07T00:15:38.233

    Thanks for clarifying. Just regarding 5 and 6, does "10" must be included mean the character 1 then the character 0, or something that represents the number ten? I think that's what I was confused about. – Sp3000 – 2016-01-07T00:23:51.363

    @Sp3000 1 then 0 immediately after. Imagine if I use Find on your code and search for 10. If it doesn't exist, it's not a valid entry. – rybo111 – 2016-01-07T00:27:20.683

    k, that makes sense. Sorry for the question barrage! – Sp3000 – 2016-01-07T00:30:31.313

    Clarification about Pyth: T is a variable, not a constant. – isaacg – 2016-01-08T09:19:38.403

    Answers

    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.
    

    Dennis

    Posted 2016-01-06T13:19:29.257

    Reputation: 196 637

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

    Explanation coming soon;

    Blue

    Posted 2016-01-06T13:19:29.257

    Reputation: 1 986

    5"Explanation coming soon;" I think we have a different understanding of 'soon'. ;P – Kevin Cruijssen – 2017-04-05T14:03:16.530

    1@KevinCruijssen Whoops, I completely forgot about this. ... And now I don't understand how it works anymore. Great. – Blue – 2017-04-28T22:15:18.560

    5

    Pyth, 16 bytes

    +/109876 54-3 21
    

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

    Try it here.

    lirtosiast

    Posted 2016-01-06T13:19:29.257

    Reputation: 20 331

    4

    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.

    lirtosiast

    Posted 2016-01-06T13:19:29.257

    Reputation: 20 331

    1Also valid in Japt, and probably some others. – ETHproductions – 2016-01-06T19:02:24.290

    1Also works in PowerShell, and Mathematica (Wolfram), and I would imagine many, many others. And probably works in dozens more with trivial modifications. – AdmBorkBork – 2016-01-06T19:19:09.670

    A lovely polyglot solution – TanMath – 2016-01-06T19:36:12.050

    If you want to take the other languages, I'll delete my community wiki one. – Addison Crump – 2016-01-06T19:39:35.917

    3

    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!

    nicael

    Posted 2016-01-06T13:19:29.257

    Reputation: 4 585

    Â == ~~ :-) – ETHproductions – 2016-01-06T22:35:20.230

    109876/54-321¬f is 15 :-D – ETHproductions – 2016-01-06T22:36:22.520

    @Eth but f doesn't work, no? – nicael – 2016-01-06T22:37:24.560

    It should be fixed. But the interpreter is down for maintenance right now, I'll get it back up momentarily. – ETHproductions – 2016-01-06T22:38:01.430

    109876/54-321q)f now works. The other suggestion doesn't. – ETHproductions – 2016-01-06T22:47:42.690

    @Eth your first suggestion does work and provide the same nice 16 bytes, not going to upgrade. (Also because it'll render my answer non-competing) – nicael – 2016-01-06T22:53:12.247

    Yep, just letting you know that it works again. – ETHproductions – 2016-01-06T22:54:28.467

    3

    Matlab / Octave, 23 bytes

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

    Try it online

    Luis Mendo

    Posted 2016-01-06T13:19:29.257

    Reputation: 87 464

    3

    bc, 14

    109876/54+3-21
    

    Nothing exciting here - borrows from other answers.

    Digital Trauma

    Posted 2016-01-06T13:19:29.257

    Reputation: 64 644

    1The dc equivalent 109876 54/3+21-p scores 16, but doesn't warrant an answer of its own. – Toby Speight – 2016-01-08T08:55:21.587

    2

    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.

    nimi

    Posted 2016-01-06T13:19:29.257

    Reputation: 34 639

    2

    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.

    Erik the Outgolfer

    Posted 2016-01-06T13:19:29.257

    Reputation: 38 134

    1

    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.

    Kevin Cruijssen

    Posted 2016-01-06T13:19:29.257

    Reputation: 67 575

    1

    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;
    

    Titus

    Posted 2016-01-06T13:19:29.257

    Reputation: 13 814

    1

    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)

    Addison Crump

    Posted 2016-01-06T13:19:29.257

    Reputation: 10 763

    1And, what's the point? – nicael – 2016-01-06T19:34:07.350

    @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. – Addison Crump – 2016-01-06T19:38:45.057

    This is not a valid answer as it does not constitute a full program or function (AFAIK) in any of the specified languages. – Alex A. – 2016-01-06T20:34:17.863

    @AlexA. It works fine here (Japt) as a full program.

    – lirtosiast – 2016-01-06T20:38:46.813

    @ThomasKwa So it's valid in 1 out of 6 of the listed languages. – Alex A. – 2016-01-06T20:42:11.680

    @AlexA. This is a full program in AppleScript. Running this through AppleScript's Script Editor or through osascript outputs the value. – Addison Crump – 2016-01-06T21:37:35.000

    Why does this have downvotes? – cat – 2016-01-06T21:46:58.653

    1Why the "function, therefore not valid" remarks? Functions are allowed by default. – nimi – 2016-01-06T21:54:32.590

    5I don't know about the other languages, but 10+9*8-7+654*3-21 is neither a JavaScript nor a Perl function. – Dennis – 2016-01-06T21:56:43.797

    @nimi The question says "print", which implies a program. – Addison Crump – 2016-01-06T22:27:08.727

    The Python REPL doesn't count as its own language – Alex A. – 2016-01-06T23:31:02.397

    @AlexA. See relevant meta discussion

    – Mego – 2016-01-06T23:58:46.487

    @FlagAsSpam: I don't see that "print" implies "program". Do we have the distinction between "print" and "output"? I can't remember, but may I err here. Default output methods for functions are their return value. Besides that, we have a meta topic that allows answers that work in repl environments, so if the repl prints for you, you're fine.

    – nimi – 2016-01-07T00:12:27.590

    @nimi Just clarified with the OP: functions are now explicitly disallowed (see main post comments) – Sp3000 – 2016-01-07T00:41:26.910

    1@Sp3000: Oh these invalidating rule changes ... – nimi – 2016-01-07T00:50:16.250

    1

    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.

    SuperJedi224

    Posted 2016-01-06T13:19:29.257

    Reputation: 11 342

    1

    ><> (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).

    torcado

    Posted 2016-01-06T13:19:29.257

    Reputation: 550

    1

    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!

    Mama Fun Roll

    Posted 2016-01-06T13:19:29.257

    Reputation: 7 234

    0

    05AB1E, 15 bytes

    109876 54÷3+21-
    

    Try it online!

    Port of Dennis' answer.

    Magic Octopus Urn

    Posted 2016-01-06T13:19:29.257

    Reputation: 19 422

    0

    Forth, 22 bytes

    Same calculation seen in other answers.

    109876 54 / 3 + 21 - .
    

    Try it online

    mbomb007

    Posted 2016-01-06T13:19:29.257

    Reputation: 21 944

    0

    C 37 bytes

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

    Same theme as many present.

    LambdaBeta

    Posted 2016-01-06T13:19:29.257

    Reputation: 2 499

    0

    VBA, 15 bytes

    ?109876\54+3-21
    

    (calculation unashamedly stolen from Dennis)

    SeanC

    Posted 2016-01-06T13:19:29.257

    Reputation: 1 117

    0

    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());

    Shaggy

    Posted 2016-01-06T13:19:29.257

    Reputation: 24 623

    0

    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
    

    Zach Gates

    Posted 2016-01-06T13:19:29.257

    Reputation: 6 152

    0

    BotEngine, 42 39 36 13x2=26

    v109876543210
    >ee   e@  eRP
    

    SuperJedi224

    Posted 2016-01-06T13:19:29.257

    Reputation: 11 342