580
\$\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
  • 1
    \$\begingroup\$ I know. That's why I posted it as a comment \$\endgroup\$ – Braden Best Apr 1 '15 at 22:51
  • 9
    \$\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

275 Answers 275

0
\$\begingroup\$

Ruby (8 bytes, 7 chars)

'ߞ'.ord

The question mark is ߞ represented in two bytes UTF8.


Short Ruby

\$\endgroup\$
  • \$\begingroup\$ Duplicate of O-I's Ruby solution posted 3.5 years earlier. \$\endgroup\$ – manatwork Jul 24 '17 at 9:24
  • \$\begingroup\$ @manatwork Duplicate answers are allowed. \$\endgroup\$ – Martin Ender Jul 24 '17 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 '17 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 '17 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 '17 at 14:29
0
\$\begingroup\$

Lua, 27 bytes

Should work in Lua 5.1, Lua 5.2, and Lua 5.3.

x="ɅɅ"print(x:byte()..#x)

Try it online!

This is mean to be saved with the UTF-8 encoding. The first byte of the string is 201, and its length is four. Lua is mostly encoding agnostic, so as long as these things are true in whatever encoding, it works.

With only ASCII, 28 bytes:

x=""io.write(x:byte(y,#x))

Note: the string must contain ASCII 20 and ASCII 14 (which are not printable characters). y here is an undefined variable, so it is nil, which byte defaults to 1 in the first parameter.

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

Pyt, 16 bytes

áŁ!⁺²Đ⁺⁺!₀⁻⁻⇹ᴇ+₅

Explanation:

á                               Push stack into list (pushes empty list)
 Ł                              Get length of top of stack (0)
  !                             0!=1
   ⁺²                           (1+1)^2=4
     Đ                          Duplicate top of stack
      ⁺⁺!                       (4+2)!=720
         ₀⁻⁻                    720/10-2=70
            ⇹                   Swap top two items on stack (4 is on top)
             ᴇ                  10^4=10000
              +₅                (10000+70)/5=2014

Try it online!

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

Brainf*ck

>++++++++++[<+++++>-]<.--.+.+++.

More readable version:

> Move pointer pos over
++++++++++ Add 10
[ Start loop
<+++++>- Add 5, move over & subtract 1
] End loop
<.--.+.+++. Do some other stuff

Yes, I know this is an old post, but I'm really bored and want to get enough rep to comment because I don't have access to my other account.

\$\endgroup\$
  • \$\begingroup\$ Welcome to PPC...Jk \$\endgroup\$ – FantaC Jan 12 '18 at 3:11
0
\$\begingroup\$

Brainfuck, 23 Bytes

-[>+<-----]>-.--.+.+++.

Try it online!

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

Aceto, 10 bytes

IIppIpPiIp

Try it online!

Uses int(Pi) to it's advantage

11 bytes (previous answer)

IIppIpIIIIp

Try it online!

Simply increments from zero 2, 0, 1, and 4 times, then prints each time

Fun Version

Piddd++DsJiPidIIJi*p

Try it online!

Uses int(Pi) to base equations off of

Lame Version

'ߞop

Try it online!

Converts the codepoint to number, which is 2014

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

PHP, 25 bytes

<?=IntlChar::ord("ߞ");?>

\$\endgroup\$
  • \$\begingroup\$ This requires the IntlChar library; and that´s a lot younger than the question. Nice idea, though. \$\endgroup\$ – Titus Mar 10 '18 at 1:31
  • \$\begingroup\$ Thanks. Can be solved without using IntlChar library with preg_replace('#\D#','',json_encode('—')). Pick your number from a unicode table :-) \$\endgroup\$ – Agnius Vasiliauskas Mar 10 '18 at 12:08
0
\$\begingroup\$

SNOBOL4 (CSNOBOL4), 42 bytes

	&UCASE 'N' @X ARB 'T' @Y
	OUTPUT =Y X
END

Try it online!

@ assigns the index of the match and (space) concatenates them.

I know, it's 2018, so I should go home...

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

Python 3, 16 bytes

lambda:ord('ߞ')

Try it online!

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

T-SQL, 32 bytes

Based on the idea of Steve Matthews, but avoiding unprintable characters:

SELECT -~(ASCII('=')*ASCII('!'))

Alternative (but rather obvious) solution, 23 bytes:

PRINT UNICODE(N'ߞ')
\$\endgroup\$
0
\$\begingroup\$

Objective-C, 27

NSLog(@"%i",'&'*('V'-'!'));
\$\endgroup\$
0
\$\begingroup\$

x86, 15 bytes

No numbers in the source code. Returns in eax. Uses (252*4 - 1) * 2.

   0:   31 c0                   xor    %eax,%eax
   2:   fe c8                   dec    %al
   4:   48                      dec    %eax
   5:   48                      dec    %eax
   6:   48                      dec    %eax
   7:   d1 e0                   shl    %eax
   9:   d1 e0                   shl    %eax
   b:   48                      dec    %eax
   c:   d1 e0                   shl    %eax
   e:   c3                      ret  

If we permit numbers in the source but not binary, we have mov $2014,%ax/ret for 5 bytes.

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

Ahead, 5 bytes

ezpz

'ߞO@

' push next cell to stack
ߞ U+7DE (2014 decimal)
O output as number
@ die

Try it online!

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

Z80Golf, 10 bytes

00000000: 080a 0b0e 767e 23e5 ee3a                 ....v~#..:

Try it online!

Disassembly

start:
  ex af,af'  ; db $3a ^ '2' ($08)
  ld a,(bc)  ; db $3a ^ '0' ($0a)
  dec bc     ; db $3a ^ '1' ($0b)
  ld c,$76   ; db $3a ^ '4' ($0e)
             ; halt         ($76)
  ld a,(hl)
  inc hl
  push hl
  xor $3a

Essentially the Hello World trick in Z80Golf.

In short, hl serves two purposes: data address for a and return address for putchar (which is at $8000 and accessed by going all the way through zeroed memory, instead of call $8000).

The instructions in the data section have to be effective no-ops (not touching hl and sp should suffice), and the last one should be 2-byte in order to shadow $76 (halt). I carefully selected the xor value so that the resulting binary has no digits ($30 to $39).

Z80Golf, 10 bytes, 2018 edition

00000000: 1416 171e 767e 23e5 ee26                 ....v~#..&

Try it online!

Disassembly

start:
  inc d      ; db $26 ^ '2' ($14)
  ld d,$17   ; db $26 ^ '0' ($16)
             ; db $26 ^ '1' ($17) ; rla
  ld e,$76   ; db $26 ^ '8' ($1e)
             ; halt         ($76)
  ld a,(hl)
  inc hl
  push hl
  xor $26

Same principle, but this time we can't use ld c,$76 since it gives $36 for the xor value. So I moved to e which starts with 1e. Also, different starting address gives two different interpretations of the data section:

  • $16 $17: ld d,$17
  • $17: rla (Rotate the register A to the left)

So I had to check both are effective no-ops in this program.

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

Lua 5.3.1, 31 bytes

It's an old question, but I may as well join in on the fun!

For those not familiar with Lua, the # operator returns the length of an array or string, and the .. operator is for string and number concatenation. The // operator is integer divide, and is used so that there is no trailing decimal in the numbers caused by Lua treating the result of regular divisions as a float.

2014 in 31 bytes: t=#"aa"print(t..t-t..t//t..t*t) = print(2..2-2..2/2..2*2)

2015 in 36 bytes: t=#"aa"print(t..t-t..t//t..t*t+t//t) = print(2..2-2..2//2..2*2+2/2)

2016 in 33 bytes: t=#"aa"print(t..t-t..t//t..t*t+t) = print(2..2-2..2//2..2*2+2)

2017 in 38 bytes: t=#"aa"print(t..t-t..t//t..t*t+t+t//t) = print(2..2-2..2//2..2*2+2+2/2)

2018 in 33 bytes: t=#"aa"print(t..t-t..t//t..t*t*t) = print(2..2-2..2//2..2*2*2)

The solutions for other years are pretty similar. Here's a function that can do any number:

function f(y)
    t=#"a"
    s=""
    for i=t, #(y.."") do
        n=t-t
        for j=t,(y..""):sub(i,i) do
            n=n+t
        end
        s=s..n
    end
    return s
end

And here's the golfed version of the function at 108 bytes:

function f(y)t=#"a"s=""for i=t,#(y.."")do n=t-t for j=t,(y..""):sub(i,i)do n=n+t end s=s..n end return s end

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

;# - 203

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#
\$\endgroup\$
  • \$\begingroup\$ This language is invalid according to the community consensus on what counts as a programming language \$\endgroup\$ – MilkyWay90 Jul 5 at 4:33
  • \$\begingroup\$ @MilkyWay90 Um, this is from just under a year ago... I don't think there was a consensus back then. Either way, it's not like i even got an upvote, so let's just leave it, eh? \$\endgroup\$ – seadoggie01 Jul 5 at 16:46
  • \$\begingroup\$ The consensus was made in 2014. You can take it up with Meta, but until then this is invalid \$\endgroup\$ – MilkyWay90 Jul 5 at 16:49
0
\$\begingroup\$

K (ngn/k), 10 bytes

"&"*-/"U "

Try it online!


and 2018 just because this is so late

K (ngn/k), 11 bytes

-"^"-*/"@!"

Try it online!


EDIT: I'm unsure when this language was created, it's a variant of k which has existed for a long time, but the gitlab link seems to indicate that it may be only a year or so old (judging by commit info), so this answer may be invalid as a result

\$\endgroup\$
  • \$\begingroup\$ The non-competing rule has been abolished \$\endgroup\$ – MilkyWay90 Jul 5 at 4:33
0
\$\begingroup\$

Aheui (esotope), 8 chars (24 bytes)

반밝따바뱟해망어

Try it online!


It's too easy for Aheui since it never use any kind of digits at all.

Explanation:

# An Aheui code starts with default stack "아".
반: push 2, move cursor right by 1(→).
밝: push 7, →
따: mul(push 14), →
바: push 0, →
뱟: push 2, move cursor right by 2(→→).
해: end.
망: print as integer, →
어: move cursor left by 1(←).

Note: Print instruction moves cursor in reverse direction if current storage is empty.

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

TI-BASIC, 7 bytes

int(₁₀^(³√(tan(cosh(cos(π

A significant improvement from the previously winning 12-byte TI-BASIC answer. Using one-byte functions allows the greatest number of chances to achieve a certain value within a given byte count.

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

Forth, 29 bytes

hex fbc 'B' '!' / / decimal .

Try it online!

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

C# .NET 75 bytes

public class p{public static void Main(){System.Console.Write((int)'ߞ');}}

Just displaying the integer value of the unicode character ߞ
Try online (also has 2015-2019)

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

Python, 8 bytes

ord('ߞ')

Cheap answer to convert the UTF-16 char to its value.

\$\endgroup\$
  • \$\begingroup\$ Exact copy of MadTux's Python solution posted more than 5 years earlier. (Hint: the Leaderboard script embedded in the challenge description is the easiest way to search for the existing solutions in your chosen language, to see whether anybody got the same idea before.) \$\endgroup\$ – manatwork Aug 21 at 8:00
  • \$\begingroup\$ Oof, thanks. I looked at the leaderboard, but the Python result I found there was longer than 8 bytes. \$\endgroup\$ – GetHacked Aug 21 at 12:35
0
\$\begingroup\$

bc, 7 bytes. Try it Online!!

K*ZZ+Y

bc, 8 bytes. Try it Online!!

K*A*A+E

Which needs 14 bytes to run in bash:

bc<<<"K*A*A+E"

In bc the upper (single) letters maintan their meaning as a number in 10-36 range in any input base.

A previous approach changed the input base:

echo ibase=D\;BBC|bc

Make numeric base 13 (D) and print BBC in that base --> 2014.

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

*nix shell (POSIX/bourne) 41 bytes

a=.. c=. d=....;echo ${#a}${#b}${#c}${#d}

Other solutions

printf %x \'— # 13 characters Try it online!
echo $[x=++y+y]$?$y$[x+x] # 25 characters Try it online!

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

Base64, 9 Bytes

MjAxNA==

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

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

Python 3, 16 Bytes, 15 Characters

print(ord('ߞ'))

Try it online!

Explanation

ord returns the decimal Unicode of a character, and the decimal Unicode of ߞ happens to be 2014.

Python 2?

I tried doing the same thing in Python 2 (print ord('ߞ')), which would be 1 byte less, but this doesn't work. Why? Well, in Python 3, len('ߞ') returns 1. However, in Python 2, len('ߞ') returns 2. And since ord only takes a string of length 1 (or a char, but Python doesn't have chars), Python 2 doesn't really like that: TypeError: ord() expected a character, but string of length 2 found

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

Flobnar, 17 14 bytes

<+\@:!
+<>.!..

Try it online!

Explanation:

   @       Start, going left

  \        Push to the stack the value from the bottom row
  >

   .!..   Several print statements we will get back to
<   :!    Add the not of the top of the stack to itself
+         This is !0+!0 = 2

      .   Print the 2

     .    Print the result of the print (0)

   .!     Print the result of the not of the print (1)
  \       Continue forward after pushing the zero to the stack

<+   :!   Add the same 2 from the beginning to itself
+<        (!0 + !0)+(!0 + !0) = 4
          And print implicitly as the last value
\$\endgroup\$

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.