Take the tour ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

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.

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

share|improve this question
2  
And by "valid tokens" I mean tokens that actually represent numbers. Numerical characters being comments does not mean they are "valid". –  Joe Z. yesterday
2  
No, it has to be 2014 exactly. –  Joe Z. yesterday
28  
I am a bit confused. Why do you like to accept answers so early? –  Quincunx 23 hours ago
7  
@JoeZ. the currently accepted answer is not the shortest posted –  Jan Dvorak 20 hours ago
4  
Do we count characters or bytes? A lot of languages can take advantage of multibyte characters here, and since all the programs are rather small, this makes a lot of difference. –  daniero 19 hours ago
show 13 more comments

63 Answers

up vote 33 down vote accepted

Befunge 98 - 17 11 9 8 bytes

'-:*b-.@

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, 452-11 is the only pairing of numbers a,b where

(a,b)∈[32,126]X[10,15]^a2-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):

"ߞ".@

Old version

cdd**e-.@

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

Older version:

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

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

share|improve this answer
add comment

Ruby, 15

p Time.new.year

Temporary ;)

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 grammar:

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!
share|improve this answer
51  
Happy = Time; Happy.new.year –  Jan Dvorak yesterday
 
Specifically disallowed though :) –  hobbs 18 hours ago
2  
@hobbs No it's not; the question says nothing about this –  Doorknob of Snow 17 hours ago
4  
This will only work correctly some of the time. –  hippietrail 16 hours ago
34  
It has worked well in all tests to date –  CoderTao 15 hours ago
add comment

Python

print sum(ord(c) for c in 'Happy new year to you!')
share|improve this answer
2  
You deserve the cleverness award –  Carter Pape 13 hours ago
 
You forgot a print somewhere. Nice one otherwise :) –  Jubobs 13 hours ago
5  
wow - this is so in the spirit of this question. <3 –  Johannes 13 hours ago
2  
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. –  dansalmo 13 hours ago
2  
I only posted mine two hours before yours. This one is not that hard to find by oneself. –  Mikaël Mayer 10 hours ago
show 3 more comments

Matlab (4 characters, 5 bytes)

The trick is to cast a string composed only of the character ߞ (of UTF-8 code point U+07DE, which corresponds to 2014 in decimal) to an integer, using the + operator:

+'ߞ'

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 (33 27 characters, as many bytes)

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

An even shorter alternative (proposed by Joseph Wright) is

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

XeTeX/LuaTeX (14 characters, 15 bytes)

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

\number`ߞ\bye
share|improve this answer
add comment

C

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

33 characters

share|improve this answer
3  
How annoying that the prime factorization of 2014 requires ASCII 5! –  Ben Jackson yesterday
add comment

PHP (9 bytes)

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
share|improve this answer
 
This looks neat, but I can't tell what is happening. Can you link to a run on ideone or phpfiddle (or something similar)? –  Quincunx 22 hours ago
 
@Quincunx: Uploading this was relatively tricky, but here is Ideone - ideone.com/APHKhn. –  GlitchMr 22 hours ago
 
This looks interesting; what does it do? –  Quincunx 22 hours ago
2  
@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. –  GlitchMr 22 hours ago
add comment

Python, 26

print int('bbc',ord("\r"))
share|improve this answer
 
Can you explain what this does? –  Quincunx 22 hours ago
2  
bbc is 2014 in base 13 –  Darren Stone 22 hours ago
 
Would've been my approach. Until I saw the accepted answer... –  Derija93 14 hours ago
add comment

Scala REPL

34 characters. Not the shortest. toInt is required to print the value of the char.

"Happy new year to you!".sum.toInt

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

'@'*' '-'"'

or

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

which have 11 and 23 chars respectively.

share|improve this answer
1  
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. –  GlitchMr 14 hours ago
 
I added a golfed version. –  Mikaël Mayer 13 hours ago
add comment

72 45 characters in the code; Zero character codes

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

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.

Shorter Javascript version (68 characters):

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

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.

share|improve this answer
1  
+1 for the "purity of purpose" of your solution. –  Joe Z. 15 hours ago
add comment

Python

newYear = '''
   _ _      _ _      /|     |     | 
  /   \    /   \    / |     |     | 
 |    /   |     |     |     |_ _ _| 
     /    |     |     |           | 
   _/_ _   \_ _/   _ _|_ _        | '''
print(newYear)
share|improve this answer
add comment

Javascript / Base 64 Conversion

alert(atob("MjAxNA=="))

23 chars (16 with atob by itself)

Or

alert("MMXIV") // ;)
share|improve this answer
2  
MMXIV has no characters in common with 2014, last I checked... // ;) –  Joe Z. yesterday
5  
The ancient Romans might disagree. The first one produces 2014 though, in modern English. –  logic8 yesterday
1  
Your first one doesn't output though... –  Doorknob of Snow 17 hours ago
 
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. –  logic8 15 hours ago
add comment

Ruby, 20

p 'bbc'.to_i ?\r.ord

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

share|improve this answer
6  
"Nobody writes jokes in base 13!" –  Jean-Michaël Celerier 21 hours ago
 
w=?$;"^XA[_AXeMFGIAHJLjKNAEFEJJNHQHNKLAEMINJOJOHLAGKHOJOJ[AG[HQHRFJAH}IHAIGGwIIA‌​HHGwKHAHGHrEUAGQFiGVAGQGfIPAFHKHHbJHAQII]MGASHNSOHATIdIAUJJRLIAWLIQGKAZOFUA]ZAeSA‌​iPAjOAkLA".codepoints{|r|r-=68;$><<(r<0??\n:(w=w==?$?' ':?$)*r)} –  Darren Stone 15 hours ago
1  
+1 just for base 13! –  Thorbjørn Ravn Andersen 12 hours ago
add comment

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'ߞ'
share|improve this answer
1  
Unfortunately, answers that only work for this year are invalid. –  Joe Z. 17 hours ago
 
I don't know APL: is that square box an APL char, or am I missing a font representation (Chrome) ? –  Carl Witthoft 17 hours ago
 
@JoeZ.: The question doesn't say that but I've added one that doesn't rely on it being 2014. –  marinus 16 hours ago
 
@CarlWitthoft: It's called a quad (), it's supposed to look like that. –  marinus 16 hours ago
add comment

GolfScript, 14

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

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).

share|improve this answer
 
The + at the end is unnecessary. Also, rather than increment 5 times, just add five. Total savings: 4 chars. '-+,/'{5+}% –  Quincunx 22 hours ago
6  
@Quincunx, 5 is a number. –  Peter Taylor 22 hours ago
 
@Quincunx Thanks, edited –  Doorknob of Snow 20 hours ago
1  
@PeterTaylor I keep forgetting. –  Quincunx 16 hours ago
 
Clever solution –  Sumurai8 1 hour ago
add comment

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

Update: altered to use say instead of print as per @PeterTaylor's comment. Not only does this shave off two further characters, it adds an attractive line break at the end of the output.

Perl - 16 (or even 14) characters

print'````'^RPQT

Using bitwise "or" on the two four-character strings "RPQT" and "````".

You can knock a couple of characters using die instead of print. However, this results in output to STDERR instead of STDOUT, and the output will be suffixed with the line number of the error. So I class that as a cheat.

(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.)

share|improve this answer
 
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? –  Dom Hastings 21 hours ago
 
It's considered acceptable to specify that you're using Perl 5 and use say for no penalty. –  Peter Taylor 21 hours ago
 
Thanks for confirming! –  Dom Hastings 21 hours ago
 
@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. –  tobyink 19 hours ago
1  
Relevant meta answer –  Peter Taylor 19 hours ago
show 1 more comment

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

TextRecognize@enter image description here

share|improve this answer
6  
Actually, you should count bytes so it's 14 + the size of the bitmap image. –  Sylwester 14 hours ago
1  
The bitmap would probably be 7,357 characters, really. –  Joe Z. 14 hours ago
1  
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. –  Jan Dvorak 14 hours ago
 
You are all killjoys. Fine, use First@ToCharacterCode@"ߞ" for 25 characters, 26 bytes. –  Michael Stern 14 hours ago
2  
As a bonus, here's a Mathematica solution in 30 characters --URLFetch@"goo.gl/miVwHe"; –  Michael Stern 13 hours ago
show 2 more comments

dc, 6 chars

$ dc <<< "DiBBCp"
2014

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

share|improve this answer
add comment

Powershell, 9

+"ߞ"[""]

ߞ (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.

share|improve this answer
 
According to codegolf.stackexchange.com/tags/code-golf/info, it should count as 9 characters. –  GlitchMr 22 hours ago
 
@GlitchMr, thanks, I've corrected my answer. –  Danko Durbić 22 hours ago
add comment

Python, 32 chars

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

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

share|improve this answer
 
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. –  Quincunx 23 hours ago
1  
Also, with your version, a=ord('.');print(a*a-ord('f')) is 2 chars shorter. –  Quincunx 23 hours ago
 
@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) –  Kroltan 17 hours ago
add comment

GolfScript (10 8 7 chars)

This solution contains non-printable characters. As xxd output:

0000000: 2714 0e27 7b7d 2f                        '..'{}/

As base 64:

JxQOJ3t9Lw==

Unpacks the ASCII codes for characters 20 and 14 and prints those numbers without any separation.

To actually generate the number 2014, I'm currently at 8 chars:

0000000: 2713 6a27 7b2a 7d2a                      '.j'{*}*

JxNqJ3sqfSo=

Takes a string containing characters with ASCII values 19 and 106 and multiplies them to get 2014.

share|improve this answer
 
Does it really take 3 characters to output the ascii codes for a string? That's sad :/ –  aditsu 21 hours ago
add comment

Mathematica, 20 bytes

ToCharacterCode@"ߞ"

(Using the 2014 unicode char)

enter image description here

share|improve this answer
 
That returns a list. To return only the desired string without using any numbers, try First@ToCharacterCode@"ߞ". That's 25 characters, 26 bytes. –  Michael Stern 14 hours ago
 
@MichaelStern Hmm I would think a List is OK. –  Ajasja 12 hours ago
add comment

Python 32 10 bytes, 91 85 (66 with math imported by default) bytes pure math

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 (32 chars):

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

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

>>> ord(u'ߞ')
2014

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)
share|improve this answer
add comment

Golfscript - 11 10 chars

'&~I'{}/-*

computes 38 * 53 (ie an expansion of the prime factorization of 2014: 2 * 19 * 53)


Old Version

'f.'{}/.*\-

This computes 462-102.

'f.'{}/ puts the ascii values of f and . on the stack.
.*      squares the value of the .
\-      swaps the two values, then subtracts
share|improve this answer
 
Interestingly, the Befunge version of this Golfscript ('&~I'{}/-*), "&~I"-*.@, is one char longer than my Befunge answer and one character shorter than Golfscript. –  Quincunx 23 hours ago
1  
Note that 2*9=18; what you meant was 2*19=38. –  Kyle Kanos 15 hours ago
add comment

Forth, 14

'> '" * '^ - .      
share|improve this answer
 
Can you explain how this works? –  ProgramFOX 22 hours ago
1  
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). –  Darren Stone 22 hours ago
add comment

GolfScript, 10

I can't beat Quincunx's 10-char plain ascii solution but I can match it:

'N,,'{}/*+

(it calculates 44*44+78)

And now a different approach :)

'codegolfing is yummy'{+}*
share|improve this answer
1  
Yet another 10-char solution: "xr"{`(;}% (free bonus smiley included!) –  Ilmari Karonen 18 hours ago
add comment

Yet another GolfScript entry, 9 printable characters

I believe this is shorter than any of the printable GolfScript entries so far:

"!="{*}*)

(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. ;-)

share|improve this answer
 
You win (for ascii golfscript) –  aditsu 16 hours ago
add comment

Haskell, 23 characters, 24 bytes

main=print$fromEnum 'ߞ'

That's U+07DE N'Ko letter KA

share|improve this answer
 
According to codegolf.stackexchange.com/tags/code-golf/info, it has 24 characters. –  GlitchMr 22 hours ago
 
Methinks that's 23 characters, @GlitchMr, though it may be 24 bytes. –  TRiG 15 hours ago
 
@TRiG: Well, yes. The info page says that "If you use Unicode, byte count should use UTF-8." –  GlitchMr 14 hours ago
add comment

Morse Code 23

;)

..--- ----- .---- ....-
share|improve this answer
1  
"in any language in which numbers are valid tokens" –  Doorknob of Snow 10 hours ago
 
"..---" is a valid token, in 5 strokes, for the number two, right? Just as "4" is a valid token, in three strokes, for the number "four". –  David Carraher 10 hours ago
 
No, the question said that numbers have to be valid in the language you're using. . and - aren't numbers. –  Doorknob of Snow 10 hours ago
add comment

Javascript, 18 characters

alert(btoa('ÛMx'))

JSFiddle: http://jsfiddle.net/pBjL2/

share|improve this answer
add comment

D

ϯ has the numerical value 1007 in Unicode encoding.

as compiler message during compilation (20 chars)

pragma(msg,'ϯ'+'ϯ');

runtime version (45 chars)

import std.stdio;void main(){write('ϯ'+'ϯ');}
share|improve this answer
add comment

protected by Community 10 hours ago

This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation on this site.

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