572
\$\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\$
  • 9
    \$\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

265 Answers 265

3
\$\begingroup\$

LiveScript, 18 bytes

The temporary solution

new Date!.getYear!

Unicode

\ߞ .charCodeAt!

Over Excitement

x=!Happy
Happy = -> console.log it
New = -> +it
Year = ->++x and Year
Year.valueOf = -> x

Happy New Year!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
\$\endgroup\$
  • 4
    \$\begingroup\$ I initially assumed that you mean LiveScript, as in, JavaScript in first Netscape 2 beta. \$\endgroup\$ – Konrad Borowski Jan 2 '14 at 13:51
  • 1
    \$\begingroup\$ @GlitchMr, that's where the name came from :-) \$\endgroup\$ – Brigand Jan 2 '14 at 20:06
3
\$\begingroup\$

JSFuck, 1267 bytes

In Javascript, here is the alert(2014) ! (Try in browser Console).

[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]][([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]((![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]+(!![]+[])[+[]]+(![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[!+[]+!+[]+[+[]]]+[!+[]+!+[]]+[+[]]+[+!+[]]+[!+[]+!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[!+[]+!+[]+[+[]]])()

This sample uses only six different characters to write and execute code. This was generated by https://github.com/aemkei/jsfuck.

\$\endgroup\$
  • 1
    \$\begingroup\$ Even though it's the longest answer rather than the shortest, +1 for JSFuck. \$\endgroup\$ – Joe Z. Jan 1 '14 at 21:04
3
\$\begingroup\$

Haskell, 69 bytes

How do you get a number without using any digits in the source? Lots of people had already done it with characters or strings, so I decided to use pi, predefined in most languages. From pi, you can get the numbers 3 and 4 easily using the ceiling and floor functions. Then you can use some combination of addition, subtraction, multiplication, and maybe division to get 2014. Just by experimenting around, it would be easy to figure out a function that takes in 3 and 4 and returns 2014 (such as 4^4 * 4 + 3^3*3^3 + 4*(3^4) - 4*4*4 + 4 - 3 = 2014). This one's 70 characters:

main=print$(\x y->y^y*y+x^x*x^x+y*x^y-y*y*y+y-x)(floor pi)$ceiling pi

Now, that's fine, but writing a function like that isn't much different than just repeatedly writing floor(pi) and ceiling(pi). Is it doable with only one pi? Well, in Haskell, functions can be treated as Monads with an instance defined in Control.Monad.Instances:

instance Monad ((->) r) where
        return = const
        f >>= k = \ r -> k (f r) r

So you can use the bind function to pass one value into two different functions: g (f x) (h x) can be rewritten f >>= flip (g.h). id >>= f can be used to pass the one value twice into the same function: id >>= (^) for example is a function that returns x to the x power. The resulting program at 207 characters is more obfuscated than golfed, but it was fun to write:

import Control.Monad.Instances
main=print.((id>>=(^)>>=flip((+).(id>>=(+)>>=flip((+).(id>>=(-)>>=flip((+).(id>>=div))))))).floor>>=flip((-).(id>>=(^)>>=flip((*).(round.sqrt.fromInteger>>=(*)))).ceiling))$pi
\$\endgroup\$
3
\$\begingroup\$

VB.NET, 59 bytes

MsgBox(((Asc(vbTab) + Asc(vbTab)) & Asc("~")) / Asc(vbTab))

takes the ascii values of a Tab twice (18) concats the ascii value of "~" (126), giving "18126" and then divides the lot by ascii of a Tab (9) = 2014

Alternatively, you can do

MsgBox Asc("j") * vbKeyPause

i.e. ascii of "j" (106) * value of the constant vbKeyPause (19), for a total of 28 characters (less than half the original).

\$\endgroup\$
  • \$\begingroup\$ The exact same code works for VB6 too. \$\endgroup\$ – Rob Jan 4 '14 at 0:06
  • \$\begingroup\$ user14566 suggested this edit: 27 bytes: MsgBox(Asc("") & Asc("")) =20 =14 \$\endgroup\$ – Justin Jan 13 '14 at 7:05
  • 2
    \$\begingroup\$ You can run this in the immediate window of VBA as ?Asc("j")*vbKeyPause, which shortens it up a bit. \$\endgroup\$ – Gaffi Mar 5 '14 at 16:46
3
\$\begingroup\$

R, 39 31 bytes:

x=T+T;x^(x*x*x+x)*x-x^(x*x)*x-x

R, also 39 31 bytes:

x=T+T;z=x*x;x^(z*x+x)*x-x^z*x-x

Thanks Scrooble!

More entertaining version: 46 bytes

z=pi;x=z*z;y=exp;j=z/y(z);floor(y(x)/(x-j-j))

Not especially efficient, but I had a lot of fun messing around with this. I'm sure there's a shorter way using just those two numbers

Long-form, subbing in the variables: floor(exp(pi*pi)/((pi*pi) - pi/exp(pi) - pi/exp(pi))

In real-person numbers: floor(19333.69 / (9.869604 - 0.1357605 - 0.1357605)) = floor(2014.328)

\$\endgroup\$
3
\$\begingroup\$

Javascript, 6 characters (8 bytes)

I never saw any rule saying we had to produce the number 2014 in the absence of any other output.
(Nor anything about not outputting to an error, but that's more obvious.)

new`—`

For me, on Firefox Nightly, this produces TypeError: "\u2014" is not a constructor, which contains the number 2014.

(If it isn't obvious, this happens because the em dash, —, is U+2014. Or, in other terms, it's the unicode character that can be represented by the hexadecimal number 2014.)

\$\endgroup\$
2
\$\begingroup\$

PHP (21 chars)

<?=ord('').ord(''); //These are not empty strings ;)

If you don't believe it, see the proof.

\$\endgroup\$
  • \$\begingroup\$ That looks like 19 characters to me. \$\endgroup\$ – Joe Z. Jan 2 '14 at 15:06
  • 1
    \$\begingroup\$ (Oh wait, nonprintables.) \$\endgroup\$ – Joe Z. Jan 2 '14 at 15:07
  • 1
    \$\begingroup\$ If it contains non-printables, you should provide a hex dump or list them. \$\endgroup\$ – mbomb007 Mar 4 '16 at 20:06
2
\$\begingroup\$

Clojure (177 characters)

In the true Lisp-ish spirit that "too many parentheses are never enough" I present:

(Integer. (clojure.string/join [(+ (second (range))  (second (range))) (first (range)) (second (range)) (+ (second (range)) (second (range)) (second (range)) (second (range)))]))

How it works:
The function range produces a lazy sequence of numbers. If no starting point and ending point are specified the range starts at zero and extends infinitely in the positive direction; however, because it's a lazy sequence the numbers are not produced until needed. Thus, applying the first function to the result of the range function without arguments produces the value 0, which is the first element in the sequence 0 to positive infinity. Applying the function second to such a range produces the value 1. From there it's a simple matter of producing enough 1's and summing them up to get 2 and 4, then converting them (implicitly) into strings to join then together, then converting the resulting string back to an integer. (I find it amusing that this is actually longer than some of the Brainf*ck answers - and to add to the horror, it's also legible :-).

Share and enjoy.

:-)

\$\endgroup\$
  • \$\begingroup\$ I suppose that you don't need to convert back to integer, instead add an output function. \$\endgroup\$ – Paŭlo Ebermann Jan 5 '14 at 18:15
  • \$\begingroup\$ Do you need all that whitespace? \$\endgroup\$ – cat Apr 18 '16 at 2:38
2
\$\begingroup\$

Python 51

Using true = 1 and false = 0

t=True
print str(t+t)+str(t-t)+str(+t)+str(t+t+t+t)
\$\endgroup\$
  • \$\begingroup\$ clever. 40 chars in PHP: $t=true;echo $t+$t.$t-$t.$t.$t+$t+$t+$t; \$\endgroup\$ – zamnuts Jan 5 '14 at 10:08
  • \$\begingroup\$ Damn just wrote that while reading the answers well done, \$\endgroup\$ – Noelkd Jan 5 '14 at 10:37
2
\$\begingroup\$

C, 31 bytes -- without a multi-character literal

main(){printf("%o",'\xe'*'J');}
\$\endgroup\$
  • \$\begingroup\$ Save 3 bytes by shortening main to f, since we don't require main to be used. \$\endgroup\$ – MD XF May 12 '17 at 19:52
2
\$\begingroup\$

Python, 30 chars

s=int('RZ',ord('$'));print s+s

2014 => 2 * 1007 => RZ in base 36 => ascii code for $ character

In interpreted mode, without the print statement it is 24 chars:

s=int('RZ',ord('$'));s+s
\$\endgroup\$
2
\$\begingroup\$

Fortran: (43 27)

print*,z'FBC'/len('hi');end

Thanks to Hristo Iliev, the above is about 40% smaller! z'FBC' returns the decimal form of that hex value (which is 4028), len returns the length of hi (i.e.,2).


Original answer:

print*,ichar(',')*ichar(',')+ichar('N');end

Converts the string , and N to ASCII values: 44 & 78 respectively: 44**2 + 78 = 1936 + 78 = 2014.

\$\endgroup\$
  • \$\begingroup\$ Shorter version using hexadecimal literals: print*,z'FBC'/len('hi');end. \$\endgroup\$ – Hristo Iliev Jan 8 '14 at 12:31
  • \$\begingroup\$ @HristoIliev: Totally forgot about printing hex via z! Thanks a bunch! \$\endgroup\$ – Kyle Kanos Jan 8 '14 at 14:51
2
\$\begingroup\$

Bash, 29 bytes

Bash without using external programs:

echo $((x=++y+y))$?$y$((x+x))
\$\endgroup\$
2
\$\begingroup\$

~-~! (No Comment), 41

Pretty basic solution.

'=~~~~~:''=~~,','@'':@''-~~:@''-~:@''+~~:

Pretty good for just 8 unique characters, eh? xD So this could theoretically be stored in 123 bits, or ~15.4 bytes.

\$\endgroup\$
2
\$\begingroup\$

k [16 chars]

(*/"i"$".,")-@""
2014

Explanation

Get the ASCII value of ",.".

"i"$".,"
46 44

Find the product

*/"i"$".,"
2024

Get the data type of char.

@""
10h

On running the complete code (2024-10)

(*/"i"$".,")-@""
2014
\$\endgroup\$
  • 1
    \$\begingroup\$ 12 chars: +/&" ~~~~h'"; 6 chars, 7 bytes, unicodey: `i$"ߞ" \$\endgroup\$ – zgrep Apr 13 '17 at 13:00
2
\$\begingroup\$

><> (9 bytes ASCII)

In pure ASCII,

'd!:'*+n;

This pushes d, !, and : to the stack, then multiplies the numerical values of top two entries, and adds the value of the last entry before outputting the value on top of the stack as a number and ending.

Using Unicode this can be reduced to 6 bytes:

'ߞ'n;

Simply outputs the numerical value of and ends.

\$\endgroup\$
  • 1
    \$\begingroup\$ You could shorten 'ߞ'n; to 'n;ߞ, I believe. \$\endgroup\$ – Addison Crump Nov 1 '15 at 12:03
2
\$\begingroup\$

Julia, 13 characters

('x'-'e')*'j'

In Julia, most arithmetic operations, when applied to a single character, convert this character to its ASCII integer value. x, e and j are respectively 120, 101 and 106, therefore (120-101)*106 is 19*106=2014.

julia> ('x'-'e')*'j'
2014

Edit: 11 characters, thanks to Glen O

A different choice of characters allows us to skip parentheses:

'.'*'.'-'f'
\$\endgroup\$
  • \$\begingroup\$ Just thought I'd point out that a different sequence can save you a few characters. For instance, '.'*'.'-'f' is only 11 characters. \$\endgroup\$ – Glen O Jun 6 '14 at 3:36
  • \$\begingroup\$ @GlenO thanks! I added it as an edit. \$\endgroup\$ – plannapus Jun 6 '14 at 7:15
2
\$\begingroup\$

J (13)

#.a.i.'_!!! '

Interprets the ASCII value of _!!! (95 33 33 33 32) as a binary number (it's weird that this is possible, I agree). This produces 2014.

J (15)

This one doesn't use any character strings. It's based on the weird coincidence that the sum of the first 46 primes is 4028: double 2014.

-:+/p:i.<:+:_bn

If anyone knows of a shorter way than <:+:_bn to represent 45 (preferably without strings), please let me know.

\$\endgroup\$
2
\$\begingroup\$

awk (28)

There's definitely a need for an "awky" answer... ;-)

BEGIN{print++I+I--I++I++I*I}

...oookaaayyy... the last * may be a + too. But please don't call it an "awkf*ck" solution then... ;-)

BEGIN{print++I+I--I++I++I+I}

I think, I prefer the later version now because of less different characters...

(tested with gawk and mawk)

\$\endgroup\$
2
\$\begingroup\$

C#, 4 characters, 5 bytes

+'ߞ'

Note: you need LINQPad to run it, not Visual Studio. LinqPad is good for CodeGolfing in C#.

\$\endgroup\$
  • 1
    \$\begingroup\$ It's 4 characters, yes, but 5 bytes. \$\endgroup\$ – Joe Z. Sep 20 '14 at 17:37
  • \$\begingroup\$ @JoeZ. ok, updated to reflect the number of bytes. Still way better than previous 63 and 64 bytes solutions. \$\endgroup\$ – Cœur Sep 21 '14 at 17:45
2
\$\begingroup\$

JavaScript, 24 bytes

A bit long, but no idea how this way got left out...

alert("ߞ".charCodeAt())

Explanation

The character ߞ is obtained by doing String.fromCharCode(2014) . Thus the code is actually just converting that character back to its character code and alerting it.

Thanks to hsl for this shorter version

\$\endgroup\$
  • \$\begingroup\$ That code doesn't work. Did you mean alert("ߞ".charCodeAt())? \$\endgroup\$ – NinjaBearMonkey Dec 27 '14 at 21:12
  • \$\begingroup\$ @hsl String.charCodeAt is present only in Firefox, it seems. But I'll use charCodeAt since its multi browser and shorter . Thanks! \$\endgroup\$ – Optimizer Dec 27 '14 at 21:25
2
\$\begingroup\$

Python 2 (19 bytes, ASCII only, CPython-specific)

print hash("w_'qe")

Tested only on 64-bit, but I assume/hope that since 2014 is small and positive the results would be the same on 32-bit? Originally tested on Python 3, but ProgramFOX confirms it also works on Python 2.

Python 3 (31 bytes, ASCII only)

print(ord("\N{NKO LETTER KA}"))

Quite fond of this one, even though better solutions exist. The equivalent Python 2 code is no shorter, as it required a u string prefix.

\$\endgroup\$
  • 1
    \$\begingroup\$ I tested on Python 2.7, and it works fine there; so you can save one character. \$\endgroup\$ – ProgramFOX Jan 1 '15 at 16:40
  • \$\begingroup\$ I found the same python 3 version, but shorter (16 bytes) as I didn’t restrict myself to ASCII :print(ord('ߞ')) \$\endgroup\$ – Frédéric Grosshans Nov 4 '15 at 14:37
2
\$\begingroup\$

Insomnia, 7

Each line is one program doing the same thing: print 2014 to output stream.

e}u#Hi-
e}u#Hs-
e}u#H}-
e}g#*i-
e}g#*s-
e}g#*}-
e}gKHi-
e}gKH}-
e}gKxi-
e}gKxs-
e}gKx}-
e}u#dK-
e}u#eK-
e}u#fK-
e}gKdK-
e}gKeK-
e}gKfK-
\$\endgroup\$
2
\$\begingroup\$

CMD - 42 bytes

set/aa=f
set/a%a%xAAA-%a%xFF-%a%xFF-%a%xCE

The 'trick' is that when using the /a switch on the set command, letters (and other invalid characters) are evaluated as 0. I then just use hexadecimal to evaluate 2014. The 0 is needed because in CMD hexadecimal must be expressed with the leading 0x. There is almost definitely a shorter way to get to 2014...

%a%xAAA - %a%xFF - %a%xFF - %a%xCE = 2730 - 255 - 255 - 206 = 2014
\$\endgroup\$
2
\$\begingroup\$

Python (30 chars)

(10 + 9) * 106 = 2014

(ord('\t')+ord('\n'))*ord('j')
\$\endgroup\$
2
\$\begingroup\$

Hassium, 77 Bytes

Really excited about this one. It gets Math.pi and divides it by itself in variable a (1), then uses increment and basic math operators to get it to 2014.

use Math;func main(){a=Math.pi;a/=a;print(++a)print(a-a)print(a/a)print(a*a)}

Run online and see expanded here

\$\endgroup\$
2
\$\begingroup\$

Milky Way 1.0.0, 22 bytes

<^a:::+;:l+:>h<::++-<-

Explanation

<          <     <   # rotate the stack leftward
 ^                   # pop the TOS without outputting
  a                  # logical not on the TOS
   :::  :   ::       # duplicate the TOS
      +       ++     # push the sum the top two stack elements
       ;             # swap the top two stack elements
         >           # rotate the stack rightward
          h          # push the TOS to the power of the second stack element
                - -  # push the difference of the top two stack elements

The stack defaults to ["", 0].


Stack Visualization

["", 0]                # default stack

[0, ""]                # <
[0]                    # ^
[1]                    # a
[1, 1, 1, 1]           # :::
[1, 1, 2]              # +
[1, 2, 1]              # ;
[1, 2, 1, 1]           # :
[1, 2, 1, 10]          # l
[1, 2, 11]             # +
[1, 2, 11, 11]         # :
[11, 1, 2, 11]         # >
[11, 1, 2048]          # h
[1, 2048, 11]          # <
[1, 2048, 11, 11, 11]  # ::
[1, 2048, 33]          # ++
[1, 2015]              # -
[2015, 1]              # <
[2014]                 # -

By default, if nothing has been output manually, the bottom stack item is output on termination of the program.


Milky Way (current version), 8 bytes

XZ*W+U+!

Explanation

X         # push 20 to the stack
 Z        # push 100 to the stack
  *       # push the product of the TOS and STOS
   W      # push 10 to the stack
    + +   # push the sum of the TOS and STOS
     U    # push 4 to the stack
       !  # output the TOS
\$\endgroup\$
2
\$\begingroup\$

Jolf, 3 bytes

(It's almost 2016. Language obviously postdates question.)

@ߞ
@  Get charcode of next character
 ߞ charcode 2014
\$\endgroup\$
2
\$\begingroup\$

JavaScript, 9 bytes

btoa`ÛMx`

This Base-64 encodes ÛMx to make 2014.

\$\endgroup\$
2
\$\begingroup\$

Lua, 32 bytes

print(#'XX'..#''..#'X'..#'XXXX')

This makes use of the length operator # used on string literals to get numbers, and the lengths are concatenated (with ..) to print 2014

\$\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.