602
\$\begingroup\$

Note to challenge writers as per meta consensus: This question was well-received when it was posted, but challenges like this, asking answerers to Do X without using Y are likely to be poorly received. Try using the sandbox to get feedback on if you want to post a similar challenge.


It's 2017 2018 2019 2020 2021 already, folks, go home.

So, now that it's 2014, it's time for a code question involving the number 2014.

Your task is to make a program that prints the number 2014, without using any of the characters 0123456789 in your code, and independently of any external variables such as the date or time or a random seed.

The shortest code (counting in bytes) to do so in any language in which numbers are valid tokens wins.


Leaderboard:

var QUESTION_ID=17005,OVERRIDE_USER=7110;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

\$\endgroup\$
15
  • 15
    \$\begingroup\$ Even though numbers are ignored in brainfuck, I thought I'd post one anyway. 32 Chars: ++++++[>++++++++<-]>++.--.+.+++. \$\endgroup\$ – Braden Best Apr 1 '15 at 21:37
  • 6
    \$\begingroup\$ Brainfuck isn't a valid language for this challenge. \$\endgroup\$ – Joe Z. Apr 1 '15 at 22:49
  • 6
    \$\begingroup\$ I know. That's why I posted it as a comment \$\endgroup\$ – Braden Best Apr 1 '15 at 22:51
  • 10
    \$\begingroup\$ I wonder if this question gets a small spike in popularity around New Year's. \$\endgroup\$ – Joe Z. Dec 26 '15 at 23:28
  • 3
    \$\begingroup\$ Waiting for "Come on folks, don't you realize it's 2016?" :) \$\endgroup\$ – padawan Jan 4 '16 at 23:35

303 Answers 303

1
\$\begingroup\$

@, 9 chars

-Σ*{~~}82

Explanation (syntactically invalid)

-       2  Subtract the result by 2(2014)
 Σ         Summation of all ASCII codes in the string(2016)
  *    8   Duplicate the string 8 times
   {~~}    Define the string "~~"

There is no Try It Online for @.

If the current year is 2016, it would be perfect(7 chars):

Σ*{~~}8
\$\endgroup\$
1
\$\begingroup\$

Base64, 9 Bytes

MjAxNA==

(You can decode it with: echo MjAxNA== |base64 -d)

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

Javascript, 45 characters

_=> new Date().getFullYear()-new Date().getDate()

Very Temporary!!

Another Day, another very Temporary answer :-)

f=new Date().getFullYear()-new Date().getDay()
\$\endgroup\$
2
  • \$\begingroup\$ Welcome to Code Golf! Submissions should be either a full program or a function, so I would recommend prepending _=> to your solution to turn it into an anonymous function. \$\endgroup\$ – Stephen Sep 5 '19 at 20:00
  • \$\begingroup\$ You could possibly remove the space between => and new to save a byte \$\endgroup\$ – Benji Mar 19 '20 at 15:26
1
\$\begingroup\$

Triangular, 12 bytes

tE**%Cdd.`>/

Try it online!

Y'know, I was just about to post a 14-byte solution; luckily I went back to double-check and had a hunch.

Ungolfed:

    t 
   E * 
  * % C 
 d d . ` 
> /

-- Actual Execution Order --

t*C`          The first multiplication does nothing.
              12 is pushed twice, then direction changes and both are multiplied to get 144.

E*d>/d%       Push 14, then multiply 14*144=2016. Decrement twice and print.


The 14-byte I was going to post:

t*CE.`*...>dd%
\$\endgroup\$
1
\$\begingroup\$

Wren, 27 bytes

Just like most other answers, convert to code points and print. However this uses control characters in the source code.

System.printAll("".bytes)

Try it online!

Explanation

                ""        // An unprintable chain containing 0x14 (20 in decimal) and 0x0e (14 in decimal)
                  .bytes  // Convert them to a list of their decimal codes [20, 14]
System.printAll(        ) // Print them all without a separator (2014)
\$\endgroup\$
1
\$\begingroup\$

><>, 7 bytes

aa+nen;

You can try it on The Online ><> interpreter.

Explanation

a        # push 10
 a       # push 10
  +      # push sum of top two values (10 + 10 = 20)
   n     # output top value as number
    e    # push 14
     n   # output top value as number
      ;  # halt program

This doesn't print the following:

20
14

because n outputs the top value as a number without a newline.

Alternate Solution (9 bytes)

This one actually puts 2014 on the stack as a single number and outputs it.

cbde**+n;

I basically just tried random values for this one :P

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

ABC, 11 bytes

aacncacaaac

Explanation

a increments the accumulator, c outputs it and n sets it to 0.

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

W j, 4 bytes

ë‘"C

Explanation

ë‘"  % Push a list
   C % Convert to list of ord codes [20,14]

flag:j % Join without a separator
```
\$\endgroup\$
1
\$\begingroup\$

MathGolf, 2 bytes

ID

Try it online!

Explanation

I   # push 20
 D  # push 14
    # implicit output
\$\endgroup\$
1
\$\begingroup\$

Spice, 145 97 bytes

Improvement using multiplication to get the 9 from 2*2*2+1, as we already had those values.

;t;z;o;n;i@LEN i z;ADD i i i;LEN i o;PUT i i i;LEN i t;MUL t t i;MUL t i i;ADD o i n;OUT t z o n;

Un-golfed explanation

;t;z;o;n;i@ - Declare vars
LEN i z;    - Get the length of [], 0, and store in z
ADD i i i;  - Adding implicitly uses the first element, or 0 if there is none, so we insert 0 into i
LEN i o;    - Store length of [0], 1, in o
PUT i i i;  - Insert 0th element of i into i at position i[0] (we're increasing the array size)
LEN i t;    - Store length of [0, 0], 2, into t
MUL t t i;  - Multiply t, 2, by itself and store in i
MUL t i i;  - Multiply t, 2, by i, 4, and store in i
ADD o i n;  - Add o, 1, to i, 8 and store in n
OUT t z o n;- Write to console - "[2] [0] [1] [9]"

Original

;t;z;o;n;i@LEN i z;ADD i i i;LEN i o;PUT i i i;LEN i t;PUT i i i;PUT i i i;PUT i i i;PUT i i i;PUT i i i;PUT i i i;PUT i i i;LEN i n;OUT t z o n;

Un-golfed explanation

In Spice, all variables are double arrays. Importantly, variables that have no assigned value are either treated as an empty list [] or 0 depending on the operation. The built-in LEN will give the length of an array and we can therefore produce numbers:

;t;z;o;n;i@ - Declare vars
LEN i z;    - Get the length of [], 0, and store in z
ADD i i i;  - Adding implicitly uses the first element, or 0 if there is none, so we insert 0 into i
LEN i o;    - Store length of [0], 1, in o
PUT i i i;  - Insert 0th element of i into i at position i[0] (we're increasing the array size)
LEN i t;    - Store length of [0, 0], 2, into t
PUT i i i;  - Now repeat until there are 9 elements...
PUT i i i;
PUT i i i;
PUT i i i;
PUT i i i;
PUT i i i;
PUT i i i;
LEN i n;     - ... and store in n
OUT t z o n; - Write to console - "[2] [0] [1] [9]"

For the original 2014 version, you save bytes for less PUTs - 95 bytes. So this solution will improve next year!

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

FEU, 69 bytes

a/abcdeghij
m/a/bb/b/cc/c/dd/d/ee/e/ff/f/gg/g/hh/h/ii/i/jj/j/kk/g
U/k

Try it online!

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

Excel, 12

=UNICODE("ߞ

Second best I could do was =ARABIC("MMXIV at 14 bytes.

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

Jelly, 10 bytes

⁹⁴×H_⁴Ḥ¤’’

Explanation:

⁹            Set the current value to 256.
 ⁴×          Multiply by 16. The current value is now 4096.
   H         Divide by 2. The current value is now 2048.
    _⁴Ḥ¤     Subtract by 16/2. The current value is now 2016.
        ’’   Decrement twice. The current value is now 2014.
\$\endgroup\$
0
1
\$\begingroup\$

MAWP, 30 28 bytes

!!+!!!!++!*+/!+!!+!+!!++++*:

Try it!

This will be fun to golf.

This is longer than @Lyxal 's answer, but outputs only one time as one number.

\$\endgroup\$
1
  • \$\begingroup\$ 15 bytes \$\endgroup\$ – lyxal Sep 28 '20 at 9:10
1
\$\begingroup\$

Poetic, 112 bytes

two`s a bad thing
using a two?o,hardly!i am using a poem
a numeric poem?oh,clearly,but a limited one for certain

Try it online!

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

DROL, 13 bytes

ziill<ukl<dfo

I wanted to add a language that wasn't already included...

DROL is a limited instruction assembler-like language with only two registers as storage. The language does include numbers, so it think it qualifies for this question. But numbers are only used for loop length indicators, as well as being used as the name of some instructions. It's described on the Esolang Wiki DROL page.

Here's a rundown of what the code does:

z              set R1=0
 ii            increment R1 by 1 twice   (2)
   ll          square R1 three two      (16)
     <         shift left R1            (32)
      u        set R2=R1                (32)
       k       increment R2             (33)
        l      square R1              (1024)
         <     shift left R1          (2048)
          d    decrement R1           (2047)
           f   subtract R1 = R1 - R2  (2014)
            o  print R1 as an integer
\$\endgroup\$
1
\$\begingroup\$

Kotlin, 42 bytes

fun main()=print("ް.".map{it.code}.sum())

I used U+1968 which is ް and a . which is U+46.

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

Phooey, 16 bytes

=@+$i>$i=$i<@+$i

Try it online!

                 # Stk  Tape
=@+$i>$i=$i<@+$i # (0) >0  0   (initial state)
=                # (0) >1  0   tape = stack == tape to get 1
 @               #  1  >1  0   push to stack
  +              # (0) >2  0   pop; add stack to tape
   $i            # (0) >2  0   print tape as integer (2)
     >$i         # (0)  2 >0   move tape ptr right, print (0)
        =$i      # (0)  2 >1   same as above to get 1 again, print (1)
           <@    #  2  >2  1   move back, push
             +$i # (0) >4  1   add stack to tape, print (4)

Thank goodness for Phooey's = operator. This would be impossible in Foo.


Phooey, 23 19 bytes

This version actually generates the number 2014 instead of printing 2,0,1, and 4.

=@+@@@+@**@@*@+--$i

Try it online!

                    # stack       | tape
=@+@@@+@**@@*@+--$i #         (0) |    0  initial state
=                   #         (0) |    1  tape = tape == pop() (to get 1)
 @+                 #         (0) |    2  double by adding to self
   @@               #    2     2  |    2  push two copies to the stack
     @+             #    2     2  |    4  double
       @*           #    2     2  |   16  square by multiplying by self
         *          #          2  |   32  multiply by 2
          @         #    2    32  |   32  push 32 for later
           @*       #    2    32  | 1024  square
             @+     #    2    32  | 2048  double
               -    #          2  | 2016  pop and subtract
                -   #         (0) | 2014  pop and subtract
                 $i #         (0) | 2014  print 2014
\$\endgroup\$
1
\$\begingroup\$

ARM assembly, 94 85 bytes (28 bytes compiled)

Textual assembly for ARM mode.

s:subs sb,sb
adc sb,sb
add sb,sb
lsl sl,sb,sb
add sb,sl,lsl sb
rsb sb,sl,lsl sl
bx lr

A function which returns 2014 in sb (r9)

Clobbers sl (r10) and sb (r9).

Expanded version:

        // It feels so empty here...
        .globl s
s:
        // use the quirky way subs affects the flags
        // to set r9 to 1
        subs    r9, r9, r9
        adc     r9, r9, r9
        // double r9 by adding it to itself
        // lsl works just as well
        // r9 = 2
        add     r9, r9, r9
        // r10 = r9 << r9
        // r10 = 2 << 2
        // r10 = 8
        lsl     r10, r9, r9
        // r9 = r9 + (r10 << r9)
        // r9 = 2 + (8 << 2)
        // r9 = 2 + 32
        // r9 = 34
        add     r9, r9, r10, lsl r9
        // r9 = (r10 << r10) - r9
        // r9 = (8 << 8) - 34
        // r9 = 2048 - 34
        // r9 = 2014
        rsb     r9, r9, r10, lsl r10
        // Return
        bx      lr

This uses the same idea as my Phooey answer, of generating 2048, then subtracting 34. While I do have access to push and pop, ARM isn't a stack machine. It is a register machine. Additionally, we have lsl for shifting left which makes a few cases easier.

It is yet another rare case where the inverted carry flag on ARM is useful for something other than 64-bit subtraction, as it allows us to set a register to 1 when combined with adc.

Additionally, this only works in ARM mode: Thumb-2 did not show the return of shifting by register (which kinda was a dumb waste of encoding bits)

It uses the classic register names instead of the format which is r[0-15].

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

Python 3, 16 bytes

print(ord('ߞ'))

Try it online!

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

Scratch, 82 bytes

when gf clicked
say(join(length of[The year two thousnd])(length of[and   fourteen
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Happy 2021! Scratch solutions make me happy though so take your upvote :P \$\endgroup\$ – Citty Apr 13 at 13:04
  • \$\begingroup\$ Out of almost 300 answers, I was surprised that nobody had done Scratch yet! \$\endgroup\$ – Nilster Apr 13 at 13:08
1
\$\begingroup\$

CSASM v2.4.0.2, 83 bytes

func main:
push "  "
len
print
push ""
len
print
push " "
len
print
push "    "
len
print
ret
end

The only way to push numbers to the stack without using numbers is to create str instances and then get their lengths.

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

Hexagony, 3 bytes

ߞ!

Try it online!

Or if you prefer code that terminates, here's 4 bytes:

ߞ!@
\$\endgroup\$
0
\$\begingroup\$

Objective C

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy"]; 
NSLog(@"%@",[formatter stringFromDate:[NSDate date]]);
\$\endgroup\$
7
  • 1
    \$\begingroup\$ From the comments: Gelatin: “Is it acceptable to use the current year?” Joe Z.: “No, it has to be 2014 exactly.” \$\endgroup\$ – manatwork Jan 1 '14 at 13:17
  • \$\begingroup\$ Because the question is a code-golf question, please add the character count. \$\endgroup\$ – ProgramFOX Jan 1 '14 at 13:31
  • 1
    \$\begingroup\$ What happened to you, Smalltalk ? You look...different. \$\endgroup\$ – bug Jan 7 '14 at 1:17
  • \$\begingroup\$ NSLog(@"%i",'&'*('F'-'A')); \$\endgroup\$ – Albert Renshaw Feb 16 '17 at 18:57
  • 1
    \$\begingroup\$ @Cœur sorry meant this NSLog(@"%i",'&'*('V'-'!')); \$\endgroup\$ – Albert Renshaw Mar 17 '18 at 20:08
0
\$\begingroup\$

Perl, 24 bytes

print-ord(A)+ord for U,O

Pure ascii, no nonprinting characters or utf8-only characters used. Uses the 21st and 15th letters of the alphabet to print 20, 14.

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

C# (56 characters)

Class P{static void Main(){Console.Write(','*','+'N');}} 
\$\endgroup\$
5
  • \$\begingroup\$ This doesn't print anything. \$\endgroup\$ – shamp00 Jan 5 '14 at 15:05
  • \$\begingroup\$ 26 characters = 4 bytes?? I don't think so... \$\endgroup\$ – jub0bs Jan 6 '14 at 12:24
  • \$\begingroup\$ Sorry. I just included the logic only. Now I included the whole program. \$\endgroup\$ – Merin Nakarmi Jan 7 '14 at 3:34
  • \$\begingroup\$ You need System.Console to use Console. \$\endgroup\$ – shamp00 Jan 8 '14 at 14:24
  • \$\begingroup\$ using System; will be on the header. So.... \$\endgroup\$ – Merin Nakarmi Jan 8 '14 at 17:50
0
\$\begingroup\$

BAT (windows batch), 7 characters

echo %*

save as a.bat and invoke as a 2014

is there any restriction on using command line parameters? – Einacio

I don't think so, but echo $1 still has a number in it. – Joe Z.

not a so valid answer, but noone was posting an answer in this wonderful language

\$\endgroup\$
2
  • \$\begingroup\$ Does BAT have an equivalent to sh’s $@ for “all parameters”? \$\endgroup\$ – Zev Eisenberg Jan 10 '14 at 23:29
  • \$\begingroup\$ @ZevEisenberg that's what i used, altought it seems someone didn't like it \$\endgroup\$ – Einacio Jan 13 '14 at 15:14
0
\$\begingroup\$

PHP (27) - not shortest ASCII PHP but more readable

<?=hexdec($e=hexdec(E)).$e;
\$\endgroup\$
0
\$\begingroup\$

Bat (Windows batch), 13 bytes (characters)

echo.^T |od -x

(^T is one character.)

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

Bash, 15 bytes

echo "^T "|od -x

(^T is one character.)

\$\endgroup\$
1
  • \$\begingroup\$ How about: printf %x \'— 13 characters. \$\endgroup\$ – Isaac Aug 30 '19 at 22:26

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.