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
2 3 4 5
11
1406
\$\begingroup\$

Python 2, 51 bytes

print sum(ord(c) for c in 'Happy new year to you!')

Try it online!

Updated for 2015 thanks to @Frg:

print sum(ord(c) for c in 'A Happy New Year to You!')

Try it online!

Mouse over to see 2016 version:

print sum(ord(c) for c in 'Happy New Year to you!!!')

Try it online!

\$\endgroup\$
42
  • 212
    \$\begingroup\$ You deserve the cleverness award \$\endgroup\$ Jan 1, 2014 at 19:49
  • 184
    \$\begingroup\$ wow - this is so in the spirit of this question. <3 \$\endgroup\$
    – Johannes
    Jan 1, 2014 at 19:51
  • 90
    \$\begingroup\$ I was a little surprised that it was only the 4th phrase I tried after "Happy new year!", which would have been perfect for the year 1374. \$\endgroup\$
    – dansalmo
    Jan 1, 2014 at 20:14
  • 66
    \$\begingroup\$ print sum(ord(c) for c in 'HAPPY NEW YEAR To you too.') Oh wait, I'm a year late. That's 2013. \$\endgroup\$
    – Warren P
    Jan 2, 2014 at 15:31
  • 189
    \$\begingroup\$ sum(map(ord,'Happy new year to you!')) would save 7 characters. \$\endgroup\$
    – user2186
    Jan 2, 2014 at 16:19
291
\$\begingroup\$

Go, 2 bytes (UTF-16)

One unicode character (2 bytes in UTF-16, 3 bytes in UTF-8 format), output 2014 as part of an error

http://ideone.com/dRgKfk

can't load package: package : 
prog.go:1:1: illegal character U+2014 '—'
\$\endgroup\$
7
  • 12
    \$\begingroup\$ That's very clever, but the question requests a program that prints the number. \$\endgroup\$ Jan 4, 2014 at 15:18
  • 54
    \$\begingroup\$ If printed error codes count, this submission should win. \$\endgroup\$ Jan 5, 2014 at 15:51
  • 60
    \$\begingroup\$ +1. The question doesn't say, "prints only the number and nothing else". \$\endgroup\$
    – Kaz
    Jan 14, 2014 at 22:31
  • 7
    \$\begingroup\$ I don't care if its valid or not, it's pretty awesome. \$\endgroup\$ May 5, 2019 at 2:01
  • 5
    \$\begingroup\$ This is a standard loophole \$\endgroup\$
    – MilkyWay90
    Aug 3, 2019 at 4:56
260
\$\begingroup\$

Ruby, 15

p Time.new.year

Temporary ;)


Note that the section of the question

independently of any external variables such as the date or time or a random seed

was not edited in until long after I posted my answer...


Jan Dvorak offers a great alternative in the comments:

Happy = Time
Happy.new.year

But it's so unenthusiastic. I prefer:

Happy = Time
class Time; alias year! year; end

Happy.new.year!

Or even:

class Have; def self.a; A.new; end; end
class A; def happy; Time; end; end
class Time; alias year! year; end

Have.a.happy.new.year!

And here's correct English punctuation:

def noop x = nil; end
alias a noop
alias happy noop
alias new noop
alias year! noop
def Have x
    p Time.new.year
end

Have a happy new year!

Okay okay, I couldn't help it:

def noop x = nil; end
eval %w[we wish you a merry christmas! christmas and a happy new].map{|x|"alias #{x} noop"}*"\n"
def year!; p Time.new.year; end

we wish you a merry christmas! we wish you a merry christmas!
we wish you a merry christmas and a happy new year!
\$\endgroup\$
1
  • 186
    \$\begingroup\$ Happy = Time; Happy.new.year \$\endgroup\$ Jan 1, 2014 at 8:18
249
\$\begingroup\$

Befunge-98 (FBBI), 17 11 9 8 bytes

'-:*b-.@

Try it online!

Similar to the old version, but I remembered about '

'-:* pushes 45, duplicates it, then squares it, producing 2025
b-   subtracts 11 from it, resulting in 2014
.@   prints the result, then ends the program

Interestingly, \$45^2-11\$ is the only pairing of numbers a,b where $$(a,b)∈[32,126]\times[10,15]\land a^2-b=2014$$ The significance of those sets is that \$[32,126]\$ is the set of printable ascii characters and \$[10,15]\$ is the set of easily accessible Befunge numbers. I found that pair with this python program:

for a in range(32,127):
    for c in range(10,16):
        if (a**2-c)==2014:
            print("%s,%s"%(a,c))

Or, if your interpreter supports unicode, then this works:

Befunge 98 - 5 bytes (4 chars)

'ߞ.@

It at least works on http://www.quirkster.com/iano/js/befunge.html with the following code (Befunge 93 - 6 bytes / 5 chars):

"ߞ".@

Befunge-98 (FBBI), 9 bytes

Old version:

cdd**e-.@

Try it online!

computes the number, then prints it:

cdd pushes numbers to the stack so that it is this: 12,13,13
**  multiplies top three values of stack, which is now: 2028
e   pushes 14
-   subtracts the top two values of the stack, resulting in: 2014
.   prints the numerical value
@   end of program

Befunge-98 (FBBI), 17 bytes

Older version:

"*'&("#;:a`j@a+,;

Try it online!

Pushes the ascii values for 2014, -10. Then prints each after adding 10 to it.

\$\endgroup\$
12
  • 82
    \$\begingroup\$ en.wikipedia.org/wiki/Befunge ...what is this i don't even... \$\endgroup\$
    – Plato
    Jan 2, 2014 at 13:16
  • 40
    \$\begingroup\$ "The language was originally created by Chris Pressey in 1993 as an attempt to devise a language which is as hard to compile as possible"... \$\endgroup\$
    – will
    Jan 2, 2014 at 15:21
  • 7
    \$\begingroup\$ @11684 The output is rather well defined in the question. If a program printed: randomstuff2randomstuff0randomstuff1randomstuff4 I wouldn't consider it a valid solution. \$\endgroup\$
    – Cruncher
    Jan 2, 2014 at 17:45
  • 7
    \$\begingroup\$ @Plato Rather than read the wikipedia article (which only includes Befunge 93), if you want to learn about Befunge 98, read the official specs \$\endgroup\$
    – Justin
    Jan 3, 2014 at 9:06
  • 3
    \$\begingroup\$ Wiki: 'The language was originally created by Chris Pressey in 1993 as an attempt to devise a language which is as hard to compile as possible' ...but why? \$\endgroup\$ Jan 28, 2014 at 20:17
193
\$\begingroup\$

Python 2, 26 bytes

print int('bbc',ord("\r"))

Try it online!

\$\endgroup\$
10
  • 65
    \$\begingroup\$ bbc is 2014 in base 13 \$\endgroup\$ Jan 1, 2014 at 10:50
  • 74
    \$\begingroup\$ I assume the use of the characters 'bbc' and the use of base 13 is a Douglas Adams tribute. "I may be a sorry case, but I don't write jokes in base 13." \$\endgroup\$ Jan 2, 2014 at 15:34
  • 10
    \$\begingroup\$ 13 years ago. RIP. \$\endgroup\$ Jan 2, 2014 at 18:30
  • 5
    \$\begingroup\$ IMO, this answer is in "True Pythonese" \$\endgroup\$
    – kmonsoor
    Jan 4, 2014 at 15:11
  • 14
    \$\begingroup\$ @BrianMinton: The use of Base 13 is probably because it's the only base between 2 and 36 that allows the number 2014 to be represented without any of the characters 0-9. \$\endgroup\$
    – dan04
    Jan 5, 2014 at 4:25
154
\$\begingroup\$

Mouse-2002, 4 bytes.

That's 4 bytes of pure, sweet ASCII.

In Mouse, the letters of the alphabet are initialised to the values 0-25. ! is the operator for printing integers, thus this prints 20 then 14 (no intermittent newline).

U!O!

There's no online interpreter available, but here you will find an interpreter written in C (needing some tweaks before one can coerce gcc to compile it) and the same compiled interpreter for Win32 but which works perfectly on Linux with wine.

Here you can find the fixed version of the interpreter, which compiles.

\$\endgroup\$
10
  • 8
    \$\begingroup\$ Wow, this is an amazing find so much later after the challenge. And with a language so esoteric nobody here had heard of it yet! \$\endgroup\$
    – Joe Z.
    Dec 9, 2015 at 1:19
  • 5
    \$\begingroup\$ BTW: this does the same thing as CJam's KE, but is actually valid because it's a language from before 2014. \$\endgroup\$
    – Joe Z.
    Dec 9, 2015 at 1:30
  • 14
    \$\begingroup\$ The smug look on my face right now resembles that of a Fortran-77 wizard after beating some proponent of Python in a fastest-code. \$\endgroup\$
    – cat
    Dec 9, 2015 at 1:33
  • 83
    \$\begingroup\$ This a game of @cat and Mouse-2002. \$\endgroup\$ Oct 7, 2016 at 5:00
  • 8
    \$\begingroup\$ @DigitalTrauma indeed :3 \$\endgroup\$
    – cat
    Oct 7, 2016 at 6:44
151
\$\begingroup\$

MATLAB, Scala (4 characters, 5 bytes)

You can take advantage of MATLAB's (and Scala's) relatively weak type system, here. The trick is to apply the unary + operation on a string composed only of the character ߞ (of UTF-8 code point U+07DE, or 2014 in decimal). This operation implicitly converts the string to a double (in MATLAB) and to an Int (in Scala):

+'ߞ'

Byte-count details:

  • + is ASCII and counts for 1 byte
  • ' is ASCII and counts for 1 byte (but appears twice in the expression)
  • ߞ is a 2-byte UTF-8 character

Total: 5 bytes

TeX (32 26 characters, as many bytes)

\def~{\the\catcode`}~}~\\~\%\bye

An even shorter alternative (proposed by Joseph Wright) is

\number`^^T\number`^^N\bye

XeTeX/LuaTeX (13 characters, 14 bytes)

If XeTeX or LuaTeX are allowed, UTF-8 input can be used directly (as proposed by Joseph Wright):

\number`ߞ\bye
\$\endgroup\$
4
  • \$\begingroup\$ \let~\number~`^^T~`^^N\bye 25 chars/bytes. You IMHO count wrong, it's 25 for your solution as well. \$\endgroup\$
    – yo'
    Jan 2, 2014 at 19:46
  • 1
    \$\begingroup\$ @tohecz I think both our solutions are actually 26-byte long. \$\endgroup\$
    – jub0bs
    Jan 2, 2014 at 19:55
  • 1
    \$\begingroup\$ If the current year is wanted, then 13 bytes: \the\year\bye \$\endgroup\$
    – yo'
    Jan 2, 2014 at 20:03
  • 2
    \$\begingroup\$ +'ߞ' also works in Scala (and a few other languages I imagine) \$\endgroup\$
    – theon
    Jan 2, 2014 at 21:22
124
+100
\$\begingroup\$

dc, 6 bytes

DiBBCp

Try it online!

  • D pushes 13 on the stack, even tho the input radix is 10 initially
  • i changes input radix (to 13 from 10)
  • BBC is 2014 base 13.
  • p prints.

Console output:

$ dc <<< "DiBBCp"
2014
\$\endgroup\$
8
  • 12
    \$\begingroup\$ True, but the actual dc program is still DiBBCp (6 chars), the rest is just a way to run it. \$\endgroup\$
    – daniero
    Jan 3, 2014 at 17:51
  • 12
    \$\begingroup\$ I was going to upvote this but it has 42 points! uses base 13 and the word BBC. How cool is that! Seems that this year we will find the question for life, universe and everithing ;-) en.wikipedia.org/wiki/Base_13. I am upvoting @daniero's comment instead and leave the answer with this magnificent 42 reputation ;-) \$\endgroup\$ Jan 12, 2014 at 19:01
  • 6
    \$\begingroup\$ @PabloMarin-Garcia, unfortunatelly some unaware person broke it... Has 43 votes now. Please go back and downvote! :) \$\endgroup\$
    – Tomas
    Jan 14, 2014 at 16:07
  • 5
    \$\begingroup\$ @Tomas Vogons always the Vogons. Resistance is futile against the intergalactic burocracy. \$\endgroup\$ Jan 15, 2014 at 0:03
  • 3
    \$\begingroup\$ I cannot even find the D command in the man page. What does it do? Never mind... D is hex for 13. \$\endgroup\$
    – kzh
    Apr 28, 2014 at 18:40
96
\$\begingroup\$

Scala, 32 29 bytes

+"Happy new year to you!".sum

Try it online!

Well ok if you really want it golfed with any chars, you can use:

Scala, 11 bytes

'@'*' '-'"'

Try it online!

Scala, 22 bytes

"{yz}"map(_-'I'toChar)

Try it online!

\$\endgroup\$
4
  • 4
    \$\begingroup\$ Interesting idea, even if it's not particularly golfed. But the string itself makes it more interesting, than something using high bytes, or something like that. \$\endgroup\$
    – 0..
    Jan 1, 2014 at 19:32
  • \$\begingroup\$ I added a golfed version. \$\endgroup\$ Jan 1, 2014 at 20:12
  • 2
    \$\begingroup\$ You could save a couple characters from the toInt like this: +"Happy new year to you!".sum Test \$\endgroup\$
    – theon
    Jan 2, 2014 at 21:26
  • \$\begingroup\$ Updated. I did not know that + could also be a prefix. \$\endgroup\$ Jan 3, 2014 at 9:49
91
\$\begingroup\$

R, 72 45 bytes

This is far from the shortest answer posted, but no one has yet posted an answer that

  • doesn't use character codes as a substitute for numbers, and
  • doesn't call the system date.

Using pure math (okay, and an automatic boolean conversion) in R, from the R console:

x<-(T+T);x+floor(exp(pi)^x)*x*x-(x*x)^(x*x)/x

Try it online!

Prints out the number 2014. T is a pre-defined synonym for true in R. The floor and exp functions are directly available in the base package, as is the pi constant. R doesn't have an increment operator, but repeating the (x*x) turned out to be fewer characters that doing increment and decrement twice each.


Original version in Javascript (72 characters)

For the simple reason that I could test out in the console, and it doesn't mind a complete lack of whitespace:

m=Math;p=m.pow;t=true;++t+m.floor(p(m.exp(m.PI),t))*t*t++-p(++t,t--)/--t

run in your console and it will print back the number 2014.


Props to xkcd (and also) for getting me to think about exp(pi): e to the pi Minus pi

P.S. If you can make the same algorithm shorter in a different language, post a comment with it.

\$\endgroup\$
11
  • 1
    \$\begingroup\$ o=!"";(o+o)+""+(o-o)+(o+o-o)+(o+o+o+o) \$\endgroup\$ Jan 2, 2014 at 10:32
  • 5
    \$\begingroup\$ 25 bytes: alert('ߞ'.charCodeAt()) \$\endgroup\$
    – oberhamsi
    Jan 2, 2014 at 14:13
  • 1
    \$\begingroup\$ +1. However, you claim your answer was the first answer that "doesn't use character codes as a substitute for numbers, and doesn't call the system date". That is actually false. My answer has this solution cdd**e-.@ (posted before yours) which does not make use of character codes or system date. It computes the number 2014. c,d, and e are hexadecimal number digits. a,b,...,f push (respectively) 10,11,...15 so 12 * 13 * 13 - 14 is the computation. \$\endgroup\$
    – Justin
    Jan 4, 2014 at 9:19
  • \$\begingroup\$ This wasn't the first answer to not use character codes; I have several earlier ones. \$\endgroup\$
    – Timtech
    Jan 4, 2014 at 12:39
  • 1
    \$\begingroup\$ @Quincunx: you're right; skimming through I didn't catch that your version was using hex digits, not character codes. \$\endgroup\$
    – AmeliaBR
    Jan 4, 2014 at 15:47
71
\$\begingroup\$

C (clang), 33 bytes

main(){printf("%d",'A'*' '-'B');}

Try it online!

\$\endgroup\$
6
  • 21
    \$\begingroup\$ How annoying that the prime factorization of 2014 requires ASCII 5! \$\endgroup\$ Jan 1, 2014 at 8:56
  • \$\begingroup\$ I got for(int a;YES;a++){NSLog(@"%i",a);} for Cocoa Touch objective C but I can't add yet (not rated enough). It does show a 2014 eventually and it has a compiler error and is possible it may not work at all and compiled is probably about 4.2 meg - but hey. \$\endgroup\$ Jan 3, 2014 at 17:21
  • \$\begingroup\$ main(){printf("%d",'\a\xde');} \$\endgroup\$
    – mjy
    Jan 5, 2014 at 15:07
  • 1
    \$\begingroup\$ @mjy Byte order of multi-character literals is not guaranteed. \$\endgroup\$ Jan 5, 2014 at 22:14
  • \$\begingroup\$ @JonathonReinhart multi-character literals are entirely implementation-defind. \$\endgroup\$
    – FUZxxl
    Apr 8, 2015 at 12:14
70
\$\begingroup\$

Python3.4.0b2 (0 bytes)

% python3.4  
Python 3.4.0b2 (v3.4.0b2:ba32913eb13e, Jan  5 2014, 11:02:52) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 
\$\endgroup\$
5
  • \$\begingroup\$ This won't work once people update their version of Python 3 a year from now. \$\endgroup\$
    – Joe Z.
    Jan 11, 2014 at 22:51
  • 26
    \$\begingroup\$ That's why I mentioned python3.4.0b2, It wont happen twice. Its release date, not system date. \$\endgroup\$
    – YOU
    Jan 12, 2014 at 3:18
  • 7
    \$\begingroup\$ This made me smile! \$\endgroup\$ Aug 2, 2014 at 11:24
  • 2
    \$\begingroup\$ Also works in Python 3.4.2. \$\endgroup\$ Sep 14, 2016 at 17:56
  • \$\begingroup\$ You are not allowed to add extraneous output. \$\endgroup\$
    – MilkyWay90
    Jul 5, 2019 at 4:31
70
\$\begingroup\$

PHP, 9 bytes

This requires PHP 7.1 or lower. It will work in PHP 7.2, but it will result in a warning. No guarantees for any future version.

xxd needed because of binary data (so copying and pasting it would be easier). May return E_NOTICE, but it doesn't really matter, does it?

~ $ xxd -r > 2014.php
0000000: 3c3f 3d7e cdcf cecb 3b                   <?=~....;
~ $ php 2014.php
2014

Alternatively, save this using ISO-8859-1 encoding.

<?=~ÍÏÎË;
\$\endgroup\$
7
  • \$\begingroup\$ @Quincunx: Uploading this was relatively tricky, but here is Ideone - ideone.com/APHKhn. \$\endgroup\$
    – 0..
    Jan 1, 2014 at 10:47
  • 1
    \$\begingroup\$ This looks interesting; what does it do? \$\endgroup\$
    – Justin
    Jan 1, 2014 at 10:48
  • 7
    \$\begingroup\$ @Quincunx: It does bitwise not (0x00 changes into 0xFF, and 0x7F changes into 0x80) on every character of the string. As the string is valid identifier (anything with high bit set is an identifier character for PHP, probably to support other encodings), PHP thinks it's a constant, but because it's not defined, it treats it as a string. \$\endgroup\$
    – 0..
    Jan 1, 2014 at 10:50
  • 2
    \$\begingroup\$ Since the question was "Now that it is 2014...", how about echo date('Y');? \$\endgroup\$
    – John
    Jan 2, 2014 at 19:05
  • 6
    \$\begingroup\$ @John: Nope. If you would read the comments for the question, you would notice that OP doesn't want the to get current year as an answer. Besides, <?=date(Y); would be 11 characters, and I have solution in 9 characters. \$\endgroup\$
    – 0..
    Jan 3, 2014 at 12:39
59
\$\begingroup\$

Mathematica, 14 characters (or 15 if you count the bitmap as a character)

TextRecognize@enter image description here

\$\endgroup\$
8
  • 54
    \$\begingroup\$ Actually, you should count bytes so it's 14 + the size of the bitmap image. \$\endgroup\$
    – Sylwester
    Jan 1, 2014 at 18:46
  • 23
    \$\begingroup\$ The bitmap would probably be 7,357 characters, really. \$\endgroup\$
    – Joe Z.
    Jan 1, 2014 at 18:46
  • 5
    \$\begingroup\$ Also, I believe some of the bytes in the image fall into the \d range. Namely, if it's the GIF, then the header itself is guaranteed to contain some. \$\endgroup\$ Jan 1, 2014 at 18:49
  • 15
    \$\begingroup\$ You are all killjoys. Fine, use First@ToCharacterCode@"ߞ" for 25 characters, 26 bytes. \$\endgroup\$ Jan 1, 2014 at 18:59
  • 9
    \$\begingroup\$ As a bonus, here's a Mathematica solution in 30 characters --URLFetch@"goo.gl/miVwHe" \$\endgroup\$ Jan 1, 2014 at 19:42
49
\$\begingroup\$

JavaScript (Node.js), 23 bytes

Uses Base 64 Conversion

alert(atob("MjAxNA=="))

Try it online!

Or

alert("MMXIV") // ;)
\$\endgroup\$
13
  • 27
    \$\begingroup\$ MMXIV has no characters in common with 2014, last I checked... // ;) \$\endgroup\$
    – Joe Z.
    Jan 1, 2014 at 6:45
  • 23
    \$\begingroup\$ The ancient Romans might disagree. The first one produces 2014 though, in modern English. \$\endgroup\$
    – logic8
    Jan 1, 2014 at 6:48
  • 1
    \$\begingroup\$ Your first one doesn't output though... \$\endgroup\$
    – Doorknob
    Jan 1, 2014 at 16:14
  • 1
    \$\begingroup\$ if you open the console in chrome, paste it and hit enter it returns the value - I'll add an alert to it as its longer than others anyway. \$\endgroup\$
    – logic8
    Jan 1, 2014 at 17:54
  • 5
    \$\begingroup\$ @logic8: Nice one +1. Another JavaScript version which also works: (4 bytes) [!+[]+!+[]]+[+[]]+[+!+[]]+[!+[]+!+[]+!+[]+!+[]] - alert([!+[]+!+[]]+[+[]]+[+!+[]]+[!+[]+!+[]+!+[]+!+[]]); Though I'm not sure it meets Joe Z's requirements. \$\endgroup\$
    – Nope
    Jan 3, 2014 at 15:03
44
\$\begingroup\$

Perl - 10 characters

This solution is courtesy of BrowserUK on PerlMonks, though I've shaved off some unnecessary punctuation and whitespace from the solution he posted. It's a bitwise "not" on a four character binary string.

say~"ÍÏÎË"

The characters displayed above represent the binary octets cd:cf:ce:cb, and are how they appear in ISO-8859-1 and ISO-8859-15.

Here's the entire script in hex, plus an example running it:

$ hexcat ~/tmp/ten-stroke.pl
73:61:79:7e:22:cd:cf:ce:cb:22
$ perl -M5.010 ~/tmp/ten-stroke.pl
2014

Perl (without high bits) - 14 characters

say'````'^RPQT

This uses a bitwise "or" on the two four-character strings "RPQT" and "````" (that is, four backticks).

$ ~/tmp/fourteen-stroke.pl
73:61:79:27:60:60:60:60:27:5e:52:50:51:54
$ perl -M5.010 ~/tmp/fourteen-stroke.pl
2014

(I initially had the two strings the other way around, which required whitespace between print and RPQT to separate the tokens. @DomHastings pointed out that by switching them around I could save a character.)

Perl (cheating) - 8 characters

This is probably not within the spirit of the competition, but hdb on PerlMonks has pointed out that Perl provides a variable called $0 that contains the name of the current program being executed. If we're allowed to name the file containing the script "2014", then $0 will be equal to 2014. $0 contains a digit, so we can't use it directly, but ${...} containing an expression that evaluates to 0 will be OK; for example:

say${$|}

For consistency, let's do the hexcat-then-perl thing with that:

$ hexcat 2014
73:61:79:24:7b:24:7c:7d
$ perl -M5.010 2014
2014

I think this is cheating, but it's an interesting solution nonetheless, so worth mentioning.

\$\endgroup\$
6
  • 2
    \$\begingroup\$ Hey there, if you reverse the string and barewords, you can save a char: print"````"^RPQT. It might be possible to use say too on 5.10+ using -E instead of -e, but I don't know if that incurs a +2 penalty for different command-line args? \$\endgroup\$ Jan 1, 2014 at 11:54
  • 3
    \$\begingroup\$ It's considered acceptable to specify that you're using Perl 5 and use say for no penalty. \$\endgroup\$ Jan 1, 2014 at 12:04
  • \$\begingroup\$ @DomHastings, personally I think if you're going to do it with "-e" or "-E", I'd say that you should then have to include the entire command, including "perl -E" in your character count. \$\endgroup\$
    – tobyink
    Jan 1, 2014 at 13:35
  • 1
    \$\begingroup\$ Relevant meta answer \$\endgroup\$ Jan 1, 2014 at 14:24
  • 4
    \$\begingroup\$ You may also save another byte by using string literals that don't require quotes, such as say ABCD^srrp. \$\endgroup\$
    – primo
    Jan 9, 2014 at 17:56
41
\$\begingroup\$

Ruby, 20 bytes

p 'bbc'.to_i ?\r.ord

Try it online!

Explanation: bbc is 2014 in base 13. Shorter than Python. Not as short as Forth.

\$\endgroup\$
10
  • 24
    \$\begingroup\$ "Nobody writes jokes in base 13!" \$\endgroup\$ Jan 1, 2014 at 12:21
  • 1
    \$\begingroup\$ w=?$;"^XA[_AXeMFGIAHJLjKNAEFEJJNHQHNKLAEMINJOJOHLAGKHOJOJ[AG[HQHRFJAH}IHAIGGwIIAHHGwKHAHGHrEUAGQFiGVAGQGfIPAFHKHHbJHAQII]MGASHNSOHATIdIAUJJRLIAWLIQGKAZOFUA]ZAeSAiPAjOAkLA".codepoints{|r|r-=68;$><<(r<0??\n:(w=w==?$?' ':?$)*r)} \$\endgroup\$ Jan 1, 2014 at 17:49
  • 1
    \$\begingroup\$ p 'ߞ'.ord for a fully functional program, 'ߞ'.ord inside irb. Works on 1.9+ \$\endgroup\$ Jan 3, 2014 at 2:37
  • 1
    \$\begingroup\$ Without "strange" unicode characters: ?-*?--?\v (45 * 45 - 11) (Ruby 1.8) \$\endgroup\$ Jan 3, 2014 at 2:45
  • \$\begingroup\$ One character smaller: ?.*?.-?f (46 * 46 - 102) (Ruby 1.8 only again) \$\endgroup\$ Jan 3, 2014 at 2:58
30
\$\begingroup\$

PowerShell, 9 bytes

+"ߞ"[""]

Try it online!

ߞ (U+07DE NKO LETTER KA) is counted as two bytes according to the code-golf tag info.

[""] returns the first character from the string ("" is converted to 0). The unary plus opeartor (+) converts the character to an integer.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ According to codegolf.stackexchange.com/tags/code-golf/info, it should count as 9 characters. \$\endgroup\$
    – 0..
    Jan 1, 2014 at 11:15
  • \$\begingroup\$ @GlitchMr, thanks, I've corrected my answer. \$\endgroup\$ Jan 1, 2014 at 11:22
  • 3
    \$\begingroup\$ The [''] is a nice trick. I usually used [char] but that's indeed shorter :) \$\endgroup\$
    – Joey
    Jan 8, 2014 at 8:57
29
\$\begingroup\$

Javascript, 18 characters

alert(btoa('ÛMx'))

Update: in ES6, using a template literal can save two characters:

alert(btoa`ÛMx`)

The code above is fairly easy to understand by keeping in mind that btoa converts a string into another string according to a set of well-defined rules (RFC 4648). To see how the conversion works, we're going to write the input string "ÛMx" as a sequence of binary digits, where each character is rendered as its 8-bit character code.

Input character          |        Û |        M |        x
Character code (decimal) |      219 |       77 |      120
Character code (binary)  | 11011011 | 01001101 | 01111000

After reorganizing the binary digits in the last row in groups of 6, we get the binary representation of 4 new numbers, corresponding to the Base64 indices of the 4 characters in the string "2014".

Base64 index (binary)  | 110110 | 110100 | 110101 | 111000
Base64 index (decimal) |     54 |     52 |     53 |     56
Output character       |      2 |      0 |      1 |      4

As per HTML specification, the output characters can be retrieved from their Base64 indices according to this table: http://dev.w3.org/html5/spec-LC/webappapis.html#base64-table.

If you don't care about the details, you could let the browser do the calculations for you and find out that "ÛMx" is the result of evaluating atob('2014') in Javascript.

\$\endgroup\$
10
  • \$\begingroup\$ the question mentions printing the number. I know that evaluation in a console will lead to the result being returned, but on Code Golf it's generally expected that JS answers will include some form of IO (alert is most common). \$\endgroup\$
    – zzzzBov
    Jan 3, 2014 at 16:22
  • \$\begingroup\$ @zzzzBov Yes, my original answer included an alert call. \$\endgroup\$
    – GOTO 0
    Jan 3, 2014 at 17:21
  • \$\begingroup\$ It lists Community as having removed the alert. I wonder if the standards have changed for JS codegolf or whether it's just a change that was adopted by Community. \$\endgroup\$
    – zzzzBov
    Jan 3, 2014 at 17:28
  • \$\begingroup\$ @zzzzBov: It was a change by anonymous user accepted by SHiNKiROU and luser droog. Anyway, this edit triggered a discussion on Meta (meta.codegolf.stackexchange.com/questions/803/…). \$\endgroup\$
    – 0..
    Jan 4, 2014 at 11:19
  • \$\begingroup\$ @xfix, It's not this edit alone that caused me to ask that question on meta, I've seen enough code golfs where people get into disagreements over whether the dev console counts as printing, that I figured it was worth asking for a standard. \$\endgroup\$
    – zzzzBov
    Jan 4, 2014 at 18:12
27
\$\begingroup\$

Scala, 6 bytes

"?="##

Try it online!

(## is Scala's symbol meaning hashCode, and the Java string "?=" hashes to 2014.)

Scala, 5 bytes

+'ߞ'

Try it online!

Math on our favorite unicode character produces an Int.

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

GolfScript, 9 bytes

Yet another GolfScript entry. I believe this is shorter than any of the printable GolfScript entries so far:

"!="{*}*)

Try it online!

(Peter Taylor's 7-char entry beats it, but includes non-printable control characters.)

I call this the "that's so last year!" entry, because what it actually does is generate the number 2013 in 8 chars, as 33 × 61, and then increments it by one. ;-)

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

C (gcc), 31 bytes

main(){printf("%o",' b'/'\b');}

Try it online!

C (gcc), 32 bytes

main(){printf("%x%o",' ','\f');}

Try it online!

C (gcc), 30 bytes

main(){printf("%x",' j'^'~');}

Try it online!

C (gcc), 30 bytes

main(){printf("%d",'\a\xde');}

Try it online!

\$\endgroup\$
11
  • \$\begingroup\$ How about just "%x" and 'b'*'S' ? That's 8212 dec or 2014 hex. Saves one char one literal and two on format string. \$\endgroup\$
    – MSalters
    Jan 2, 2014 at 15:26
  • \$\begingroup\$ @MSalters No, 'b'*'S' is 8134. The prime factorization of 8212 is 2*2*2053, so I don't see an easy way to produce it. \$\endgroup\$ Jan 2, 2014 at 16:14
  • \$\begingroup\$ Bah, checked with integer division that 8212/'b' == 'S' :( \$\endgroup\$
    – MSalters
    Jan 2, 2014 at 16:37
  • \$\begingroup\$ and octal doesn't work either (02014=1036=37*28, 28 is unprintable) \$\endgroup\$
    – MSalters
    Jan 2, 2014 at 16:44
  • 1
    \$\begingroup\$ @FredOverflow what about my 28 char solution? main(){puts(__DATE__+'\a');} \$\endgroup\$ Jan 8, 2014 at 5:18
21
\$\begingroup\$

GolfScript, 14 bytes

'-+,/'{)))))}%

Try it online!

How it works: ASCII goes like this:

...
+
,
-
.
/
0
1
2
3
4
...

So, this takes the ASCII codes of each character, subtracts five, and sticks it in a string.

{...}% yields an array of the characters of a string mapped, when given a string as an argument. So, it increments each character by 5 () means increment).

\$\endgroup\$
5
  • \$\begingroup\$ The + at the end is unnecessary. Also, rather than increment 5 times, just add five. Total savings: 4 chars. '-+,/'{5+}% \$\endgroup\$
    – Justin
    Jan 1, 2014 at 10:42
  • 21
    \$\begingroup\$ @Quincunx, 5 is a number. \$\endgroup\$ Jan 1, 2014 at 10:48
  • 9
    \$\begingroup\$ @PeterTaylor I keep forgetting. \$\endgroup\$
    – Justin
    Jan 1, 2014 at 16:43
  • \$\begingroup\$ Clever solution \$\endgroup\$
    – Sumurai8
    Jan 2, 2014 at 7:38
  • \$\begingroup\$ The CJam version of this: "-+,/"_,)f+. :) (Then again, CJam has KD.) \$\endgroup\$ Dec 18, 2014 at 18:38
21
\$\begingroup\$

Forth (gforth), 14 bytes

'> '" * '^ - .

Try it online!

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Can you explain how this works? \$\endgroup\$
    – ProgramFOX
    Jan 1, 2014 at 11:04
  • 1
    \$\begingroup\$ I'm expressing integer constants as character literals using their ordinal (ASCII) values. So this is: 62 34 * 94 - . If you don't speak Forth, this means print (62 * 34 - 94). \$\endgroup\$ Jan 1, 2014 at 11:14
  • \$\begingroup\$ Forth (Gforth 0.7.0), 5 bytes, 4 chars: 'ߞ . It prints the character. \$\endgroup\$ Jan 9, 2014 at 11:03
19
\$\begingroup\$

APL (6 bytes, 4 chars)

⊃⎕TS

Only works this year though.

Why it works:

      ⎕TS
2014 1 1 11 58 5 811
      ⊃⎕TS
2014

Without relying on the system date, it's 10 bytes (7 characters):

⎕UCS'ߞ'
\$\endgroup\$
4
  • 6
    \$\begingroup\$ Unfortunately, answers that only work for this year are invalid. \$\endgroup\$
    – Joe Z.
    Jan 1, 2014 at 15:34
  • \$\begingroup\$ I don't know APL: is that square box an APL char, or am I missing a font representation (Chrome) ? \$\endgroup\$ Jan 1, 2014 at 16:24
  • \$\begingroup\$ @JoeZ.: The question doesn't say that but I've added one that doesn't rely on it being 2014. \$\endgroup\$
    – marinus
    Jan 1, 2014 at 17:12
  • 5
    \$\begingroup\$ @CarlWitthoft: It's called a quad (), it's supposed to look like that. \$\endgroup\$
    – marinus
    Jan 1, 2014 at 17:12
19
\$\begingroup\$

Python 2, 32 bytes

print ord(',')*ord('-')+ord('"')

Try it online!

Probably possible to reduce it using the 2014 th Unicode char ߞ, but I didn't try.

Quincunx notes that

a=ord('.');print a*a-ord('f')

Try it online!

is shorter by three chars.

\$\endgroup\$
6
  • \$\begingroup\$ The unicode version works, at least in Python 3 with IDLE: print(ord("ߞ")). It does not appear to work in Python 2; Python 2 probably does not support unicode. \$\endgroup\$
    – Justin
    Jan 1, 2014 at 9:59
  • 3
    \$\begingroup\$ Also, with your version, a=ord('.');print(a*a-ord('f')) is 2 chars shorter. \$\endgroup\$
    – Justin
    Jan 1, 2014 at 10:06
  • \$\begingroup\$ @Quincunx It does support, however you need to have a specific encoding set to your file and append u at the end of the string (would be "ߞ"u) \$\endgroup\$
    – Kroltan
    Jan 1, 2014 at 16:23
  • 2
    \$\begingroup\$ @Kroltan Actually, I'm pretty sure the second part is not true. In Python 2, you had to prepend strings with u to say that they were unicode, but in Python 3, all strings are automatically unicode \$\endgroup\$ Jan 2, 2014 at 15:41
  • 1
    \$\begingroup\$ Similar as commented above, without unicode print ord('.')**2-ord('f') is slightly shorter. \$\endgroup\$
    – MLS
    Jan 7, 2014 at 16:45
19
\$\begingroup\$

Python 2, 32 bytes

Had some fun writing this:

my_lst = []
for i in range(33, 126):
    for j in range(i, 126):
        if 2014 - 126 < i * j < 2014 - 33:
            if j not in range(48, 58):
                my_lst.append("ord('" + unichr(i) +
                              "')*ord('" + unichr(j) +
                              "')+ord('" + unichr(2014 - i * j) + "')")

for val in my_lst:
    print val, '->', eval(val)

Prints all the possible ways I can write 2014 using Bruno Le Floch's method:

ord('!')*ord(':')+ord('d') -> 2014
ord('!')*ord(';')+ord('C') -> 2014
ord('!')*ord('<')+ord('"') -> 2014
ord('"')*ord(':')+ord('*') -> 2014
ord(')')*ord('/')+ord('W') -> 2014
ord('*')*ord('-')+ord('|') -> 2014
ord('*')*ord('.')+ord('R') -> 2014
ord('*')*ord('/')+ord('(') -> 2014
ord('+')*ord(',')+ord('z') -> 2014
ord('+')*ord('-')+ord('O') -> 2014
ord('+')*ord('.')+ord('$') -> 2014
ord(',')*ord(',')+ord('N') -> 2014
ord(',')*ord('-')+ord('"') -> 2014

Python 2, 10 bytes

But this is obviously redundant, so if your interpreter is set to utf-8 by default, then all it takes is:

ord(u'ߞ')

Try it online!

Python 2, 83 bytes

Also, thanks to AmeliaBR (for the idea), I tried my best to implement a pure math version:

from math import*
a,b,c=int(e),round(e),ceil(pi);print int(a**(b*c-(c-b))-a*a**c-a)

Try it online!

\$\endgroup\$
6
  • \$\begingroup\$ ord(',')**2+ord('N') \$\endgroup\$
    – MLS
    Jan 7, 2014 at 16:42
  • 6
    \$\begingroup\$ @MLS Well, that has a digit in it :) \$\endgroup\$ Jan 7, 2014 at 23:00
  • 2
    \$\begingroup\$ I optimized your math version a bit: a,b=int(e),int(pi);c=a+a;print a**(b*c-c+b)-a*a**c-a, and you can eliminate the math import altogether by making use of the fact that True in Python 2.x is identical to the integer 1 in operation, bringing it down to 50 characters: o=True;a=o+o;b=a+o;c=b+o;print a**(b*c-o)-a*a**c-a \$\endgroup\$ Jan 8, 2014 at 2:19
  • \$\begingroup\$ You can save a character if you use Python 3: ord('ߞ') \$\endgroup\$
    – asmeurer
    Jan 11, 2014 at 20:24
  • \$\begingroup\$ @JoachimIsaksson A digit is no number ;) \$\endgroup\$
    – univalence
    Aug 26, 2016 at 18:50
17
\$\begingroup\$

R, 20 bytes

@popojan (he is not allowed to post an answer here yet) has provided the solution within 20 characters.

sum(T+T:exp(T+pi))-T

Try it online!

Output:

[1] 2014

R, 22 bytes

Anonymous user has suggested shorter solution.

strtoi("bbc",pi*pi+pi)

Try it online!

2014 is BBC in base 13. pi*pi+pi (=13.0112) is treated by R in this context as the integer 13. Output:

2014

R, 30 bytes

cat(a<-T+T,T-T,T/T,a*a,sep="")

Try it online!

Output:

2014

R, 31 bytes

cat(T+T,T-T,T/T,T+T+T+T,sep="")

Try it online!

Inspired from the answer by AmeliaBR. Output:

2014
\$\endgroup\$
6
  • \$\begingroup\$ Wow, +1! And I hoped my roman numerals solution will be the best... :( ;-) \$\endgroup\$
    – Tomas
    Jan 14, 2014 at 15:35
  • \$\begingroup\$ The variants below can be made shorter: cat(a<-T+T,T-T,T/T,a^a,sep="") (30 chars), paste0(aT+T,T-T,T/T,a^a) (26 chars) \$\endgroup\$
    – Tomas
    Jan 15, 2014 at 10:16
  • \$\begingroup\$ @Tomas, the function paste0 is not allowed, as it contains the symbol 0. Your solution makes 30 characters if using cat. \$\endgroup\$
    – djhurio
    Jan 21, 2014 at 10:47
  • \$\begingroup\$ create file 2014 in current directory and write list.files() - 12 characters \$\endgroup\$
    – Zbynek
    Jan 31, 2014 at 17:00
  • \$\begingroup\$ @Zbynek, I expect your solution not to be valid in the general scope of codegolf rules. \$\endgroup\$
    – djhurio
    Feb 1, 2014 at 9:19
15
\$\begingroup\$

Java (JDK), 77 75 bytes

75 characters if print is added in a class with the main method:

class C{public static void main(String[]a){System.out.print('#'*'<'-'V');}}

Try it online!

It means 35*60-86 which is equal to 2014

\$\endgroup\$
15
  • 2
    \$\begingroup\$ I like your formula. \$\endgroup\$
    – Johannes
    Jan 1, 2014 at 23:30
  • 7
    \$\begingroup\$ This actually needs to be longer, because the class definition needs to be in it to run. Shortest way I know (with Java 6):class a{static{System.out.println('#'*'<'-'V');}} \$\endgroup\$
    – Justin
    Jan 2, 2014 at 0:29
  • 1
    \$\begingroup\$ @Quincunx, with Java 7, a main method is needed \$\endgroup\$
    – True Soft
    Jan 2, 2014 at 20:53
  • 2
    \$\begingroup\$ @TrueSoft Note I said "with Java 6". You should choose the shortest Java possible. \$\endgroup\$
    – Justin
    Jan 3, 2014 at 0:43
  • 2
    \$\begingroup\$ You can remove 'ln' in println to reduce chars... \$\endgroup\$
    – laksys
    Jan 3, 2014 at 10:22
14
\$\begingroup\$

CJam, 2 bytes

KE

Try it online!

K and E are variables preset to 20 and 14.
I created CJam in 2014 so it's ok if it doesn't qualify.

\$\endgroup\$
1
2 3 4 5
11

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