577
\$\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 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\$
  • 10
    \$\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
  • 4
    \$\begingroup\$ Brainfuck isn't a valid language for this challenge. \$\endgroup\$ – Joe Z. Apr 1 '15 at 22:49
  • 8
    \$\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
  • 1
    \$\begingroup\$ @BradenBest It's possible to do it in 31 characters in at least two different ways: +++++++[>+++++++<-]>+.--.+.+++. and ++++++++++[>+++++<-]>.--.+.+++. \$\endgroup\$ – Zubin Mukerjee Feb 21 '16 at 17:47

273 Answers 273

1
\$\begingroup\$

Charcoal, 5 bytes

I²⁰¹⁴

Try it online!

Language was created after January 1, 2014, but as Charcoal uses the superindices ⁰¹²³⁴⁵⁶⁷⁸⁹ to represent the numbers, the answer is valid. :-)

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

Lua, 29 bytes

b=("").byte print(b"?"..b"?")

NB: the two question marks are substitutes for characters that are not appearing properly in the post. See the tio link below for proof.

Try it online!

As an interesting point, although this is not the case with Lua, a language with an implementation of pi to at least 3137 digits would be able to print pi and find '2014' at digits 3133-3136!

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

J, 21 bytes

,":,.$,:~}.,:,:'golf'

Try it online!

               'golf'  One dimensional array
           ,:,:        Itemize twice (1x1x4 array)
         }.            Drop first element (0x1x4)
      ,:~              Append to itself as distinct items (2x0x1x4)
     $                 Get dimensions (2 0 1 4)
   ,.                  Flatten items, essentially prints 2014 vertically.
                       (so there are no spaces)
,":                    To strings, flatten.    

20 bytes

#.(#_),,~(,~,~#_),%_
#.(#_),,~(,~$,._),%_

15 bytes

do'bbbc',~":_bd

11 bytes

,":_bk,:_be
\$\endgroup\$
1
\$\begingroup\$

√ å ı ¥ ® Ï Ø ¿, 8 bytes

TTX''_o

Try it online!

The rest of the code in the TIO link is the Python interpreter (because I can't be bothered to ask Dennis to add √ å ı ¥ ® Ï Ø ¿

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

Python, 41 bytes

print(int(ord("j")/len("aa") * ord("&")))

Try it online!

\$\endgroup\$
  • 2
    \$\begingroup\$ Welcome to the site! The aim of this question (and code golf in general) is to get the shortest functional code. You can remove the spaces around the * to start with. \$\endgroup\$ – caird coinheringaahing Jan 7 '18 at 20:51
1
\$\begingroup\$

Pyt, 9 bytes

π!⬡⁻⁻⁻△⁻⁻

Try it online!

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

LibreLogo (Paper Format: Tabloid), 55 bytes

The document must be in Tabloid Format for this method to work.

Code:

print ''.join(set(str(pagesize.pop()))).replace('.','')

Result:

enter image description here

Explanation:

pagesize                                           ; Returns [792.0, 1224.0] (Tabloid Format)
pagesize.pop()                                     ; Returns 1224.0
str(pagesize.pop())                                ; Returns "1224.0"
set(str(pagesize.pop()))                           ; Returns {u'2', u'0', u'1', u'.', u'4'}
''.join(set(str(pagesize.pop())))                  ; Returns "201.4"
''.join(set(str(pagesize.pop()))).replace('.','')  ; Returns "2014"
\$\endgroup\$
1
\$\begingroup\$

Canvas, 7 bytes

AA+q⁷┤t

Try it online!

AA       | Push 10 to stack twice
   +      | Add top two items in stack
    q     | Print top item in stack on current line
      ⁷    | Push 16 to stack
       ┤   | Decrement top item in stack twice
        t | Print top item in stack on current line, disable implicit output
\$\endgroup\$
1
\$\begingroup\$

C, 24

(Using GCC-4.9.2)

f(){printf("%i",'Þ');}         (Properly formatted version on Pastebin)


IMPORTANT NOTE: There is a U+0007 in-front of the Þ character but stackexchange removes it for some reason. Make sure you edit it back in before compiling my code. Here is a pastebin of the code that does include the unicode characters needed.

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

Perl 5 + Perligata, 25 bytes

Byte count uses the new rule that command-line switches for choosing appropriate modules don't count.

perl -MLingua::Romana::Perligata -e'MMXIVimum egresso scribe.'

Tested in Strawberry 5.26.0 with Perligata 0.601 (with " instead of ' in the above code).

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

jshell, 5 bytes

How to make Java an useful code golf language? Simple, just remove the need to declare classes, methods, make things automatically print and so on.

+'ߞ'
\$\endgroup\$
1
\$\begingroup\$

Stax, 4 bytes

ü◘♥┐

Run and debug (ha) it online!

Obligatory Stax answer. This unpacks to 2014. Implicit print.

I haven't yet found a shorter version.

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

C# (.NET Core), 42 bytes

System.Console.Write((int)'ϯ'+(int)'ϯ');

// Btw. it's now 2018 ^^ so
System.Console.Write((int)'ϱ' + (int)'ϱ');

Try it online!

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

SMBF, 15 bytes

\x00 is a literal NUL byte. This program adds 5 to each of /,+- and prints.

<[+++++.<]\x00/,+-

Only my Python interpreter can accept non-printable ASCII. Change the data line to this, and substitute the code you want to run with the non-printable values escaped (on line 169):

data = bytearray(b'the above code goes here')
\$\endgroup\$
1
\$\begingroup\$

CJam, 2 bytes

KE

K is predefined as 20, E is predefined as 14. The stack gets automatically printed after the program.

Try it online!

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

C#, 28 bytes

You don't need to cast to an int as Hille does, so it becomes

Console.WriteLine('ϱ'+'ϱ')

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

Symbolic Python, 31 bytes

_=-~-~-~(_==_)
_=`""`[_::_]

Try it online!

Symbolic Python bans numbers anyway.

Explanation:

_=-~-~-~(_==_)   # Set _ to 4
_=               # Set _ to
  `""`         # From the representation of some unprintables 
                    # Which is '\x12\x10\x11\x14'
           [_::_]   # From the 4th character, take every 4th character
                    # Output the contents of _ implicitly

A more interesting solution at 34 bytes:

_=-~(_==_)
_=`_`+`_-_`+`_/_`+`_*_`

Try it online!

_=-~(_==_)               # Set _ to 2
_=`_`+`_-_`+`_/_`+`_*_`
# '2'+'2-2'+'2/2'+'2*2' = '2'+'0'+'1'+'4' = '2014'
\$\endgroup\$
  • \$\begingroup\$ Crazy that someone else is actually using this stupid language I made, haha \$\endgroup\$ – FlipTack Dec 17 '18 at 21:01
1
\$\begingroup\$

Edited: bash 81 chars!

Just for fun:

wc -c < <(echo {,}{,,}{,}{,,,}{,}{,,,}film dbugjkqstvxz{,}{,,} 'Happy New Year!')

there is no numbers, all letters are used and this print exactly:

2014

( This method could reasonably be used until 2016: by just adding one or two exclamation point after the wish:

   wc -c < <(echo {,}{,,}{,}{,,,}{,}{,,,}film dbugjkqstvxz{,}{,,} 'Happy New Year!!')
   2015

;-)

bash 27 chars

.;v=$?;echo $v$?${#v}$[v+v]

This will output:

bash: .: filename argument required
.: usage: . filename [arguments]
2014

Ok, this will generate some unwanted output, but 2014 is printed and is a valid token!

The two following sample are error free (a little longer but near golfed)

v=$(echo {V..v});echo $[${#v}#vu]
2014

or

printf -vv "%d" $?xfbc;echo $[v>>${#?}]
2014

or even:

echo $[$[$[${#?}$?-${#?}]$?>>${#?}]#Iy]
2014

Inspired by comment from GammaFunction:

echo $[$[a-a]xfbd>>${#?}]
\$\endgroup\$
  • \$\begingroup\$ You don't need to set a var in the 0xfbc solution: echo $[$?xfbc>>++j] works just fine (19 bytes). \$\endgroup\$ – GammaFunction Mar 28 at 7:15
  • \$\begingroup\$ Nice! Late to post but you could! Unfortunely you have to ensure $? to be 0 and this could not be reused... But impressive! \$\endgroup\$ – F. Hauri Mar 28 at 15:54
  • 1
    \$\begingroup\$ @GammaFunction Post edited ;-) \$\endgroup\$ – F. Hauri Mar 28 at 16:46
1
\$\begingroup\$

C#, 25 Bytes, 24 Characters

Console.Write((int)'ߞ');

Try it online!

Explanation

The decimal Unicode of ߞ is 2014, so you can just cast it to an int and 2014 is printed.

\$\endgroup\$
  • 1
    \$\begingroup\$ Welcome! Though admittedly, the answer is simple, in general it is best to add an explanation or link to an online interpreter. Code-only answers are usually automatically flagged as low-quality, meaning that those answers have to be reviewed by someone. \$\endgroup\$ – mbomb007 Aug 30 at 21:19
  • \$\begingroup\$ @mbomb007 yeah i was thinking about adding a link to tio.run, i'll do that \$\endgroup\$ – Sagittarius Aug 31 at 9:09
1
\$\begingroup\$

05AB1E, 22 10 8 bytes

₁нTRžx¦J

Try it online!

How it works:

  • pushes 256, and н pushes the first element. We get 2.
  • T pushes 10, and R reverses it. We get 0 1.
  • žx pushes 64, and ¦ removes the first element. We get 4.

Lastly, we concatenate everything using J!

\$\endgroup\$
  • 1
    \$\begingroup\$ Hi, welcome to PPCG! See here for an existing 6- and 5-byte 05AB1E answer. But to golf your approach a bit more: 1. you can remove all « and only have a single J (join) at the end. 2. You could save values in between with © and use it later on with ® (i.e. žh¦¦©нžhнžh¦н®¦¦нJ). 3. There are builtins for the numbers 0, 1, and 2 if you don't change them later on, which are ¾, X, and Y respectively, so an alternative 6-byter could be Y¾XY·J (push 2; push 0; push 1; push 2 and double it; join all values on the stack together). \$\endgroup\$ – Kevin Cruijssen Sep 2 at 8:12
  • \$\begingroup\$ (this last one doesn't really look like your initial approach anymore, but just stating it as example). And if you haven't seen it yet, tips for golfing in 05AB1E might be interesting to read through. :) \$\endgroup\$ – Kevin Cruijssen Sep 2 at 8:13
  • \$\begingroup\$ Digits aren't allowed though. Otherwise just Ž7æ (compressed 2014) or 2014 itself would be enough. :) \$\endgroup\$ – Kevin Cruijssen Sep 4 at 10:42
  • \$\begingroup\$ @KevinCruijssen Oh, how silly. I forgot. \$\endgroup\$ – facepalm42 Sep 4 at 10:43
  • \$\begingroup\$ I've found a 10 byte solution now. I don't think there might be any room for improvement. \$\endgroup\$ – facepalm42 Sep 4 at 11:08
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\$
  • \$\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 at 20:00
0
\$\begingroup\$

Objective C

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy"]; 
NSLog(@"%@",[formatter stringFromDate:[NSDate date]]);
\$\endgroup\$
  • 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\$
  • \$\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\$
  • \$\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\$
  • \$\begingroup\$ How about: printf %x \'— 13 characters. \$\endgroup\$ – Isaac Aug 30 at 22:26
0
\$\begingroup\$

PYTHON

print(str(len('Happy new year to me')) + str(len('Happy new year')))
\$\endgroup\$
  • \$\begingroup\$ This has a 1 in it. \$\endgroup\$ – Joe Z. Jan 11 '14 at 23:16
  • \$\begingroup\$ oh whoops let me fix it \$\endgroup\$ – Oliver Ni Jan 11 '14 at 23:17
  • 1
    \$\begingroup\$ Must str('Happy new year') be wroted as str(len('Happy new year'))? \$\endgroup\$ – AMK Jan 11 '14 at 23:28
  • \$\begingroup\$ sorry. I fixed it. \$\endgroup\$ – Oliver Ni Jan 13 '14 at 4:53
0
\$\begingroup\$

PHP, 22 bytes

echo ord('').ord('')

Edit

SE is stripping the characters. Working version here: http://codepad.org/unzjXNY2.

\$\endgroup\$
  • \$\begingroup\$ this produces "00" when I run it. Please explain. \$\endgroup\$ – Darren Stone Jan 14 '14 at 20:32
  • \$\begingroup\$ SE is stripping the characters. Added a codepad example. \$\endgroup\$ – MichaelRushton Jan 14 '14 at 22:40
  • \$\begingroup\$ You can swap out echo with <?=, to make it 2 characters shorter. \$\endgroup\$ – cjfaure Feb 8 '14 at 19:36

protected by Community Jan 14 at 6:34

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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