620
\$\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 2022 2023 2024 already, folks, go home.

Woo, 10 years of this challenge!

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

328 Answers 328

1
7 8 9
10
11
0
\$\begingroup\$

Delphi (26bytes & 26 chars)

ord('-')*ord('/')-ord('e')

Ascii values
- : 45
/ : 47
e : 101
45*47 = 2115 - 101 = 2014

\$\endgroup\$
1
  • \$\begingroup\$ The specifications say “make a program that prints”. This code excerpt is merely an expression that’ll evaluate to 2014. It’s not a program nor will it print anything. Complete Pascal solution. \$\endgroup\$ Nov 6, 2022 at 10:32
0
\$\begingroup\$

You never said we couldn't put it on an external page!

Javascript - 19 Chars

location='//x.vu/u'

PS. It took 2 tries to get a shortened URL without numbers :P

\$\endgroup\$
8
  • \$\begingroup\$ Yes, but sadly your code is far from being the shortest. :P \$\endgroup\$
    – Joe Z.
    Jan 1, 2014 at 18:26
  • 1
    \$\begingroup\$ @Joe Z. Right, you could include an HTML script src instead :P \$\endgroup\$
    – Cilan
    Jan 1, 2014 at 23:10
  • \$\begingroup\$ location.href.match(/-(\d+)-/).pop() \$\endgroup\$
    – Alf Eaton
    Jan 3, 2014 at 9:18
  • \$\begingroup\$ location='http://goo.gl/miVwHe' would be shorter in my opinion. \$\endgroup\$
    – 0..
    Jan 4, 2014 at 11:23
  • \$\begingroup\$ @xfix Thanks for the tip, I even removed 'http:' :) \$\endgroup\$
    – Cilan
    Feb 8, 2014 at 19:24
0
\$\begingroup\$

e-TeX, 21 bytes

\the\numexpr`*`j\bye

It contains an invisible control character with code 19 (0x13) before the asterisk. A version with printable ASCII characters needs two more bytes:

\the\numexpr`^^S*`j\bye

In TeX ` takes the character code of the next token:

  • [0x13] (^^S): 19
  • j: 106

\numexpr calculates: 19 * 106 = 2014

The result is a DVI file with "2014" on the first page.

Variant with 2014 as page number:

\pageno\numexpr`^^S*`j~\bye

(25 bytes, if ^^S is replaced by the byte with character code 19).

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

Java without the weird unicode charas @ 115

enum A{A;public static void main(String[]z){int a=A.ordinal(),b=a++;System.out.print(""+(a<<a)+b+a+(a<<(a<<a)));}}

enumerators are pretty handy :)

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

GTB, 38

π/π→A:A++B:A+A→C:C*C→D~B*C*C+B*C-C-A-A

Compile assuming : at front

\$\endgroup\$
2
  • \$\begingroup\$ π is 2 bytes and is 3, bringing the byte count to 49. \$\endgroup\$
    – Joe Z.
    Jan 7, 2014 at 2:18
  • \$\begingroup\$ @JoeZ. All characters at tibasicdev.wikidot.com/83lgfont are 1 byte. \$\endgroup\$
    – Timtech
    Jan 7, 2014 at 12:10
0
\$\begingroup\$

Python, 8 characters

ord('ߞ')

I think this ought to be valid :P

Ok, if you want me to use print(),

15 characters

print(ord('ߞ'))
\$\endgroup\$
0
0
\$\begingroup\$

Cardinal, 14 chars

%n=*+.-d++.
 d

The pointer starts at %, reads in the character ‘d’(ASCII 100), creates a duplicate as inactive value (the bottom of the stack), adds active and inactive values, resulting in 200, adds 1, prints out the result 201, subtracts one, divides by inactive value (100), resulting in 2, adds two, prints out 4. Cardinal pointer stacks can only carry values up to 255 (OEM 437 range), everything above leads to a wrap-around.

0             100             100             200             201
0               0             100             100             100
>n=*+.-d++.    %>=*+.-d++.    %n>*+.-d++.    %n=>+.-d++.    %n=*>.-d++.
 d              d              d              d              d
———————————————————————————————————————————————————————————————————————
   201             200               2               3               4
   100             100             100             100             100
%n=*+>-d++.    %n=*+.>d++.    %n=*+.->++.    %n=*+.-d>+.    %n=*+.-d+>.

print:"201"
———————————————————————————————————————————————————————————————————————
          4
        100  
%n=*+.-d++>

  print:"4"

Result:

Executing program..

2014

Execution complete.
\$\endgroup\$
0
\$\begingroup\$

C, 24 / 68

main(){printf("MMXIV");}

Haha, Roman Numerals For The Win!


Or, for real:

main(){printf("%i%i%i%i",strlen("aa"),nil,strlen("a"),sizeof(int));}
\$\endgroup\$
0
\$\begingroup\$

q, 20 17 bytes

{x+y*z}."j"$"$+."
\$\endgroup\$
0
\$\begingroup\$

TeaScript, 7 bytes

'ߞ'c()

Takes the char code of the character with a char code of 2014

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

Groovy, 48 bytes

For 2015 change cabe to cabf...

n={it.each{print(((int)it)-(int)'a')}}
n('cabe')

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

JavaScript, 17 Bytes

atob("MjAxNA==")
\$\endgroup\$
0
\$\begingroup\$

C (gcc 5.3.1), 49 bytes

Pure arithmetic! \o/

main(a){printf("%d",(++a<<(a<<a|a))-(a<<a+a)-a);}

Undefined behaviours.

Specifically, use this compiler (languages are defined by implementation).

Without undefined behaviour (which would work on all compilers), 51 bytes

main(a){a++;printf("%d",(a<<(a<<a|a))-(a<<a+a)-a);}

Explanation

Basically 2048 - 32 - 2, constructed using powers of 2.

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

Swift 2.2, 28 bytes

print("\(ENOTDIR)\(EFAULT)")

Falling back on Darwin/glibc error codes from errno.h.

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

Mathematica, 16 bytes

FromDigits@"JAE"
\$\endgroup\$
0
\$\begingroup\$

QBIC, 10 bytes - Not Competing

?z^s*r+z+t

Calculates 2014 from the pre-initialised variables q-z (1-10) and prints it. Development of QBIC started some two years after 2014...

Alternative 12-byte version:

?(u*y)^r-z-q
\$\endgroup\$
0
\$\begingroup\$

Pushy, 6 bytes

`��`j#

Contains control characters, so here's a hexdump:

0000-0006:  60 14 0e 60 6a 23

The first unprintable is the literal DC4 byte (\x14), and the second is SHIFT-OUT (\x0e).

First these bytes are pushed as charcodes, so the stack is [20, 14]. The j operator concatenates these and # outputs the result: "2014".


10-byte solution:

`<:;>`KT-"

Uses char-code manipulation and the builtin T (10).

`<:;>`       Push string as char-codes: [60, 58, 59, 62]
     KT-     Take 10 from each: [50, 48, 49, 52]
        "    Interpret as char-codes and print: results in "2014"
\$\endgroup\$
0
\$\begingroup\$

Microscript, 10 bytes

Noncompeting, language postdates the question..

'js'(s';-*

Explanation: 106*(59-40), using the language's equivalent of character literals. I'd do 53*38, but the character corresponding to 53... is the digit 5. And the character corresponding to 19 is, of course, nonprintable, so that wouldn't work.

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

Pyke, 3 bytes, noncompetitive

Try it here!

Where ߾ is 0xDFBE

Loads ord(0xDFBD-0x20) as an integer and implicit prints it

\$\endgroup\$
2
  • \$\begingroup\$ How does it work? \$\endgroup\$
    – Pavel
    Dec 13, 2016 at 4:04
  • \$\begingroup\$ @Pavel explanation added \$\endgroup\$
    – Blue
    Dec 13, 2016 at 7:35
0
\$\begingroup\$

tcl, 16

puts [scan ߞ %c]

Can be seen on: http://rextester.com/live/SVXB29034

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

Groovy, casting to int, 8 bytes

(int)'ߞ'
\$\endgroup\$
0
\$\begingroup\$

C, 25 bytes

f(){printf("%d",L'ߞ');}

24 characters, but one character is UTF-8 encoded. Still the shortest C answer! How it works:

U+07DE ߞ NKO LETTER KA

7DE in decimal is 2014.

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

C, 29 bytes (Emacs) / 40 bytes (VI)

Before creating program, execute the shell command

stty -ixon      ### 11 bytes, with the newline

N.B this is required for most terminal editors, but is not required for emacs

then write this code:

main(){printf("%d",'j'*'^S');}

N.B. '^S' is a single XOFF character e.g. in VI use control-V, control-S; in emacs use control-Q, control-S; emacs turns off flow control by default.

I assume the comment [You can't type ^S in a Linux terminal] below left off an implied [without the stty command or equivalent e.g. emacs default behavior upon startup], otherwise that comment is inaccurate.

And here is the requested hexdump:

$ od -a -t x1 x.c
0000000   m   a   i   n   (   )   {   p   r   i   n   t   f   (   "   %
         6d  61  69  6e  28  29  7b  70  72  69  6e  74  66  28  22  25
0000020   d   "   ,   '   j   '   *   ' dc3   '   )   ;   }  nl
         64  22  2c  27  6a  27  2a  27  13  27  29  3b  7d  0a
\$\endgroup\$
3
  • 2
    \$\begingroup\$ This isn't a valid answer. You have to count the shell command also, since it's a non-standard configuration. Also, if you have unprintables in your code, you should include a hexdump, for extra clarity. \$\endgroup\$
    – user45941
    Sep 27, 2016 at 15:46
  • \$\begingroup\$ You can't type ^S in a Linux terminal. -1 \$\endgroup\$
    – MD XF
    May 21, 2017 at 23:37
  • 1
    \$\begingroup\$ There is more than one way to ^Skin a cat, so these comments are incorrect as written; I clarified my post to address the confusion these folks (and others) may be having. It's still 29 if you use emacs as an editor. MD XF: how do you enter your [U+07DE] character into C-source; also, my compiler throws an error when replacing [main()] with [f()] (excluding the obvious gcc -Df=main hack), but if there is a compiler that accepts [f()], then all C source scores drop by 3. So you need to bump your score by 3, or reduce all other C solutions. \$\endgroup\$ May 22, 2017 at 14:29
0
\$\begingroup\$

Python 3, 16 Bytes :

print(ord('ߞ'))

2017 version, 16 Bytes :

print(ord('ߡ'))
\$\endgroup\$
0
\$\begingroup\$

Whitespace, 19 bytes

Visible representation:

SSSTTTTTSTTTTSNTNST

Just pushes 2014 onto the stack and prints it. Whitespace's lack of any visible characters makes this pretty easy.

Valid as numbers are completely valid tokens in whitespace, they just don't do anything.

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

Common Lisp, 15 characters

(char-code #\ߞ)

Try it online!

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

Clojure - 35 characters ASCII only

(print(-(*(int\#)(int\<))(int\V)))

Based on True Soft's answer

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

Ruby (8 bytes, 7 chars)

'ߞ'.ord

The question mark is ߞ represented in two bytes UTF8.


Short Ruby

\$\endgroup\$
7
  • \$\begingroup\$ Duplicate of O-I's Ruby solution posted 3.5 years earlier. \$\endgroup\$
    – manatwork
    Jul 24, 2017 at 9:24
  • \$\begingroup\$ @manatwork Duplicate answers are allowed. \$\endgroup\$ Jul 24, 2017 at 10:44
  • \$\begingroup\$ I didn't said they aren't. Neither downvoted or flagged. (Just for the record, I never agreed with that rule. And never will.) But I think would be more enjoyable to avoid duplicated solutions. Especially on a question that already has 263 answers. \$\endgroup\$
    – manatwork
    Jul 24, 2017 at 11:03
  • \$\begingroup\$ Hm... hard to find the old solutions. But actually his solution is 9 bytes because the codepoints representations need 2 bytes. \$\endgroup\$
    – schmijos
    Jul 24, 2017 at 12:58
  • 1
    \$\begingroup\$ Initially O-I's solution was also 'ߞ'.ord, but then be updated because the requirement says to “prints the number 2014”. The general rule (which can be overridden by each challenge) is that solutions must handle input and output either themselves explicitly or benefit the interpreter's service if it has such thing like ruby's -n or -p. Code that expects input to be readily available in the memory or just leaves the value they produce in the memory are called snippets and generally are not accepted as solutions. \$\endgroup\$
    – manatwork
    Jul 24, 2017 at 14:29
0
\$\begingroup\$

Implicit, 3 bytes

Try it online!

     implicit push command
`    character
 ߞ   U+07DE (2014 in decimal)
     implicit integer output
\$\endgroup\$
0
\$\begingroup\$

Triangularity, 18 bytes

.. ..
."ߞ".
o    

Try it online!

\$\endgroup\$
1
7 8 9
10
11

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