579
\$\begingroup\$

Note to challenge writers as per meta consensus: This question was well-received when it was posted, but challenges like this, asking answerers to Do X without using Y are likely to be poorly received. Try using the sandbox to get feedback on if you want to post a similar challenge.


It's 2017 2018 2019 already, folks, go home.

So, now that it's 2014, it's time for a code question involving the number 2014.

Your task is to make a program that prints the number 2014, without using any of the characters 0123456789 in your code, and independently of any external variables such as the date or time or a random seed.

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


Leaderboard:

var QUESTION_ID=17005,OVERRIDE_USER=7110;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

\$\endgroup\$
  • 10
    \$\begingroup\$ Even though numbers are ignored in brainfuck, I thought I'd post one anyway. 32 Chars: ++++++[>++++++++<-]>++.--.+.+++. \$\endgroup\$ – Braden Best Apr 1 '15 at 21:37
  • 4
    \$\begingroup\$ Brainfuck isn't a valid language for this challenge. \$\endgroup\$ – Joe Z. Apr 1 '15 at 22:49
  • 8
    \$\begingroup\$ I wonder if this question gets a small spike in popularity around New Year's. \$\endgroup\$ – Joe Z. Dec 26 '15 at 23:28
  • 3
    \$\begingroup\$ Waiting for "Come on folks, don't you realize it's 2016?" :) \$\endgroup\$ – padawan Jan 4 '16 at 23:35
  • 1
    \$\begingroup\$ @BradenBest It's possible to do it in 31 characters in at least two different ways: +++++++[>+++++++<-]>+.--.+.+++. and ++++++++++[>+++++<-]>.--.+.+++. \$\endgroup\$ – Zubin Mukerjee Feb 21 '16 at 17:47

274 Answers 274

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\$
2
\$\begingroup\$

05AB1E, 6 bytes (non-competing)

T·žvÍ«

Uses the CP-1252 encoding. Try it online!

Explanation:

T       # Push 10
 ·      # Multiply by 2
  žv    # Push 16
    Í   # Subtract 2
     «  # Concatenate
        # Implicit output
\$\endgroup\$
  • \$\begingroup\$ +1 from me. Here a 6-byte alternative: Txs4+J (Push 10; Duplicate and double copy (10,20); swap; Add 4; Join together). \$\endgroup\$ – Kevin Cruijssen Sep 10 '18 at 13:31
  • \$\begingroup\$ 5-byter 'ߞÇ. Uses default ASCII encoding (so both ߞ and Ç are 2 bytes each), because ߞ doesn't exist in 05AB1E's codepage. \$\endgroup\$ – Kevin Cruijssen Jan 14 at 12:51
2
\$\begingroup\$

Brain-Flak, 50 bytes

((((((()()()()()){}){})){}{}()){()()({}[()])}{}())

Try it online!

Brain-flak is great for restricted source challenges because there are only 8 valid character to begin with: brackets. (e.g. []{}()<>).

This was made possible with the help of @ASCII-only's integer metagolfer, which is currently hosted online at brain-flak.github.io/integer

\$\endgroup\$
  • 1
    \$\begingroup\$ Using the integer metagolfer in WheatWizard's brain-flak optimizer I found ((((((()()()()()){}){})){}{}()){()()({}[()])}{}()) which is 4 bytes shorter. \$\endgroup\$ – 0 ' Dec 15 '16 at 7:30
  • \$\begingroup\$ The challenge requires languages in which 0123456789 are valid tokens. Does Brain-Flak satisfy this requirement? \$\endgroup\$ – Dennis Jan 7 '17 at 17:17
2
\$\begingroup\$

EXCEL: 148 bytes

=POWER(ROW()+ROW(),(ROW()+ROW()+ROW())*(ROW()+ROW()+ROW())+ROW()+ROW())-(POWER(ROW()+ROW(),ROW()+ROW()+ROW())*(ROW()+ROW()+ROW()+ROW())+ROW())-ROW()

only works in A1.

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

Brain-Flak, 46 + 3 = 49

Try it online

(([()]([(()()())]((((({}){}){}()){}){})))()())

This one uses the -A flag for +3 bytes. It pushes the ASCII values for 2014 to the stack which outputs as 2014 in ASCII mode.

\$\endgroup\$
  • \$\begingroup\$ The challenge requires languages in which 0123456789 are valid tokens. Does Brain-Flak satisfy this requirement? \$\endgroup\$ – Dennis Jan 7 '17 at 17:17
  • 2
    \$\begingroup\$ @Dennis yes @lt flags use decimal literals \$\endgroup\$ – Sriotchilism O'Zaic Jan 7 '17 at 21:59
2
\$\begingroup\$

Sinclair ZX81 15 bytes 10 bytes

 PRINT CODE "=";CODE ":"

As the ZX81 has a non-ASCII compatible character set, the character code for = is 20 and for : it is 14 - simples.

\$\endgroup\$
  • 1
    \$\begingroup\$ You've used a 1 in your answer. \$\endgroup\$ – caird coinheringaahing Apr 2 '17 at 1:09
  • \$\begingroup\$ There is no way around making a ZX81 BASIC program without using line numbers. You may take out the line number and run it in direct mode if you wish. \$\endgroup\$ – Shaun Bebbers Apr 2 '17 at 6:27
  • \$\begingroup\$ This is perhaps another reason why retrocomputing @ Stack Exchange should allow one-liners and code-golf therem, but apparently this would not constitute retro computing. Or something. \$\endgroup\$ – Shaun Bebbers Apr 2 '17 at 6:30
  • \$\begingroup\$ Correction on my last comment: there not therem. \$\endgroup\$ – Shaun Bebbers Apr 2 '17 at 7:24
2
\$\begingroup\$

Fourier, 12 bytes

Non-competing: Fourier is newer than the challenge

I know I'm two years too late, but it seemed like a fun challenge to do in Fourier.

^^ovvo^o^^^o

The command ^ increments the value of the accumulator (which starts at zero) and v decrements the value of the accumulator.

Try it online!

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

Lean Mean Bean Machine, 53 bytes

\\\
O))\ \
#)) o )
 ))u ))
 ))  ))
 ))  )u
 ))  ~
~~~

I like this.

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

><>, 7 bytes

aa+nen;

Try it online!

aa                      +                           n                                    e                 n                                    ;
^^                      ^                           ^                                    ^                 ^                                    ^
Push 10 to stack twice, add top two items in stack, print top item in stack as a number, push 14 to stack, print top item in stack as a number, stop.
\$\endgroup\$
  • 2
    \$\begingroup\$ 6 bytes: eaa+n< \$\endgroup\$ – Jo King Apr 12 '18 at 0:43
2
\$\begingroup\$

JavaScript, various solutions: 131, 44, 43, 30, 28, and 16 characters (16 bytes)

Original answer:

JS-fuck inspired JavaScript, 131 characters:

(!![]<<(!![]<<!![])<<!![]<<(!![]<<!![])<<!![]<<(!![]<<!![])<<!![]<<(!![]<<!![]))-((!![]<<!![])<<!![]<<(!![]<<!![])<<!![])-!![]-!![]

Shifty truth edition:

(true<<(true<<true)<<true<<(true<<true)<<true<<(true<<true)<<true<<(true<<true))-((true<<true)<<true<<(true<<true)<<true)-true-true

Addenda

Edit: I'm having too much fun with this... combining type coercion with hex strings, 44 characters.

a=+[];(a+'xade')-(a+'x'+(+!a+!a+!a)+a+a)
a=+[];(a+'xade')-(a+'x'+(++a+a+a)+--a+a)

a is 0, 0xade is 2782. We need to subtract 768 to get 2014. 768 is 0x300. (a+'x'+(+!a+!a+!a)+a+a) and (a+'x'+(++a+a+a)+--a+a) are two ways of producing "0x300", so the final result is "0xade" - "0x300", which JavaScript coerces back to numbers, resulting in 2014.

Here is a radix 36-based parseInt solution, 43 characters:

(a=+[]);parseInt(++a+'jy',a+++a+++''+(a+a))

First, we initiate a variable a at 0 (clearly this requires non-strict mode), increment it to 1, concatenate with 'jy' - 1jy happens to be 2014 in radix 36. The quickest way call parseInt at this radix is to generate the string "36" and abuse type coercion again: a++ + a++ results in 3, with a set to 3 as well, which means (a+a) is 6, so a+++a+++''+(a+a) results in "36", resulting in 2014.

After coming up with these two solutions I started looking at other JavaScript answers (thanks for the tip, Scrooble!), to see if combining ideas from other people gives interesting results.

Zaq's approach can be shortened with the hex string trick to 28 characters:

-~[]+!![]+[+[]]+ +(+[]+'xe')

How it works: -~[]+!![]+[+[]] results in "20", +[]+'xe' results in "0xe". +"0xe" is 14, so "20" + +"0xe" becomes "20" + 14, which becomes "2014".

Now here's a fun fact: 20 in hexadecimal is 0x14! Oh, and 14 is 0xe. So +('0x' + 0xe) produces 20. Combining this with the above results in a 30 character solution:

_=+[]+'x';+(_+ +(_+='e'))+[+_]"

Finally, initially inspired by Dan Prince's answer I came up with what might be the shortest possible JavaScript solution abusing hex-strings, at 16 characters:

+[]+'xfbc'>>!![]

0xfbc is 4028. Shift right by one, and we have 2014. If anyone knows of a shorter way to generate 0 or 1, let me know.

Edit2: having exhausted the hexadecimals, we should of course also look at binary and octal notation!

// +'0b11111011110'
+(a=+[],a+++'b'+(a+(((a+=[a]+a+a+(+[])))+a)))
// +'0o3736'
+(a=-~[],a=a+++a+++''+(a+a),+[]+'o'+((+a+1)+a))
\$\endgroup\$
  • 2
    \$\begingroup\$ Welcome to the site, and nice first post! \$\endgroup\$ – Khuldraeseth na'Barya Mar 8 '18 at 20:55
  • \$\begingroup\$ Thanks. Do you know of any ways to show all answers on one page so I can quickly check for duplicates next time? ;) \$\endgroup\$ – Job Mar 8 '18 at 20:57
  • 1
    \$\begingroup\$ @Job the stack snippet in the question body lists by shortest solutions and the shortest solutions by language. I've never been able to see them on mobile/in the app, though, so your mileage may vary. \$\endgroup\$ – Giuseppe Mar 8 '18 at 21:11
  • 1
    \$\begingroup\$ @Job You can do a search with inquestion. For just about all questions, there'll be just one page of results. The 17005 is this question's ID, found in the URL. \$\endgroup\$ – Khuldraeseth na'Barya Mar 8 '18 at 21:23
  • 1
    \$\begingroup\$ Thanks for the tips! Added some more solutions :) \$\endgroup\$ – Job Mar 9 '18 at 0:28
2
\$\begingroup\$

Pyt, 27 bytes

ɳąḞḞ⬠⬠⬠π⎶⁻⦋ĐąžΠ²+ĐŚřƩ½*-⁻⁻Ɩ

Try it online!

Not exactly a serious contender, just had some fun.

ɳ             push '0123456789' as string
 ą             convert to array of digits [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  ḞḞ            for each item in array, replace with xth fibonacci # (2x) [1, 1, 2, 3, 8, 34, 377, 17711, 9227465, 225851433717]
   ⬠⬠⬠          for each item in array, replace with xth pentagonal # (3x) [1, 1, 1820, 66045, 240027425, 29321506727800, 6947548864499411875070L, 165405818231059923692911546880492501L, 898044801648686628863443901192030771814779461710865094720L, 115670237695821250427139838385782853032222541808893547195455834936957002151009052998969975100L]
       π⎶⁻           push pi, round, and decrement (2)
          ⦋         get the 2th element of that list (1820)
           Đ         Duplicate 1820
            ąž        make an array of digits and remove zeroes [1, 8, 2]
              Π        multiply together (16)
               ²+       square and add (2076)
                 ĐŚ      Duplicate and sum digits (15)
                   řƩ     make a range from 1 to 15 and sum all (120)
                     ½*    multiply by 1/2 (60)
                       -    subtract  (2016.0)
                        ⁻⁻   decrement (2x)   (2014.0)
                          Ɩ   cast to integer (2014)
implicit output
\$\endgroup\$
2
\$\begingroup\$

Julia 0.6, 9 bytes

Int('ߞ')

Try it online!

Just for completeness' sake. Here's 2018 (same trick, different character):

Int('ߢ')

Try it online!

And just for fun, here's a function using bit shifting and arithmetic instead of using character codepoints (depends on this being Julia version 0.6, which seems an appropriately golf-y hack):

Julia 0.6, 47 bytes

(l=VERSION.minor,o=true)->o<<(l+l-o)-o<<~-l-o-o

Try it online!

Here, o=true evaluates as 1 during arithmetic. VERSION is an inbuilt constant containing the current Julia version, and VERSION.minor is 6 in this case. We left shift 1 by 6+6-1=11, giving 2048, then subtract 1<<(6-1)=32 and 1 and 1 from it, to give 2014.

2018 version would be:

(l=VERSION.minor,o=true)->o<<(l+l-o)-o<<~-l+o+o
\$\endgroup\$
2
\$\begingroup\$

JavaScript (ES6), 52 46 bytes

t=-~'';console.log(`${++t}${t-t}${t/t}${t*t}`)

Try it online!

Will log through console.log the number 2014 as a string.

Thanks to Jacob for multiple optimizations saving 6 bytes

Explanation

t=-~'';

In JavaScript, ~~ will convert the proceeding value to a number, in this case, true equates to 1.

Set the value of t to 1 by using ~ on an empty string, which would equate to -1, then take the opposite of that number, 1.

For more info about tilde in JavaScript, see this article.

console.log(` ... `)

Logs the template string ... with ${} expressions available, where ... includes:

${++t}

Sets w to t+t, which would be 2, which would return the number 2. Added to string.

Set t to itself + 1, and display the final result, 2

${t-t}

Displays t-t, which would be 0, which would return the number 0.

${t/t}

Takes the value of t and divides by itself, returning 1.

${t*t}

Takes the value of w*w*w*w-w (or w ^ 4 - 1), where w (as previously set) is 2, and subtracts w from it, and returns the result. Added to string.

Takes the value of t*t (or t ^ 2), where t (as previously set) is 2.

The added expressions equate to 2014, which ... is in the log.

\$\endgroup\$
  • \$\begingroup\$ Technically you don't need the ~~ before the true \$\endgroup\$ – Jo King Jun 19 '18 at 0:46
  • \$\begingroup\$ t=-~'';console.log(`${++t}${t-t}${t/t}${t*t}`) \$\endgroup\$ – Jakob Jun 19 '18 at 1:45
2
\$\begingroup\$

MathGolf, 2 bytes

ID

Try it online!

Explanation

I   Pushes 20
 D  Pushes 14

The stack is printed in full on termination.

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

Lost, 57 23 22 bytes

<^/*(
 )/@+
">>v
^?%<<

My first Lost answer. Thought I'd start with an easy one.

Byte-count more than halved (-35 bytes) thanks to @JoKing.

Try it online or verify that it's deterministic.

General explanation about Lost:

Let me start with an explanation of Lost itself. Lost is a 2D path-walking language. Most 2D path-walking languages start at the top-left position and travel towards the right by default. Lost is unique however, in that both the start position AND starting direction it travels in is completely random. So making the program deterministic, meaning it will have the same output regardless of where it starts or travels, can be quite tricky.

A Lost program of 2 rows and 5 characters per row can have 40 possible program flows. It can start on any one of the 10 characters in the program, and it can start traveling up, down, left, or right.

In Lost you therefore want to lead everything to a starting position so it follows the designed path you want it to. In addition, you'll usually have to clean up the stack when it starts somewhere in the middle.

Program explanation:

The 22-bytes program is similar as the previous 23-bytes program below, but with a smarter path to save that byte:

v<<<<<>>>>>
>%?"^ <"*+@

Let me start with an explanation of the 23-bytes program:

The "^ <" will push the character-codepoints for the three characters in the string, being 94 32 60 respectively. The * multiplies the top two, and + adds the top two of the stack, so it becomes 94+(32*60), which results in 2014.

The @ will terminate the program, but only if the safety is 'off'. When the program starts the safety is always 'on', otherwise the program starting at the exit character immediately terminates without doing anything.
The % will turn the safety 'off'. So as soon as the % is encountered and the safety is 'off', the program can be terminated with an @.

The ? is to clean up the stack if it started somewhere in the middle.

And finally the v<<<<<>>>>>, > and use of ^ < in the string are to lead the program path towards the correct starting position for it to correctly print 2014. Note that the top line could have been v<<<<<<<<<<, but that the reversed part >>>>> will wrap-around to the other side, making the path shorter and therefore the performance slightly better. The byte-count remains the same anyway, so why not.


Now for the 22-bytes solution, and how it actually is the same as the 23-bytes solution, but with a different path.

The arrows are still used to lead the path into the given direction. The / are used as a mirror. So if we go from right to left and encounter the /, it will continue downwards; if we go from the top to the bottom and encounter the /, it will continue towards the left; etc.

The ( will pop the top value on the stack and push to to the scope, and the ) will do the reversed: it pops from the scope, and pushes it back to the stack.

So regardless of where we start and in which direction we travel, the path leads towards the first < of the bottom row. From there, the program flow travels in this order:

%?^        Direction changed upwards
" <^" <    Direction changed towards the left
(*/        Direction changed downwards
/          Direction changed towards the left
) +@

So it will:

  • Turn the safety 'off' with %;
  • Clean the stack with ?;
  • Push the character-codepoints for " <^", which are 32 60 94 respectively;
  • Pop the 94 and store it in the scope with (;
  • Multiply the 32 60 with *, resulting in 1920;
  • Push the 94 from the scope back onto the stack with );
  • Add the 1920 94 together with +, resulting in 2014;
  • And then terminates the program with @, implicitly outputting the top of the stack.
\$\endgroup\$
  • 1
    \$\begingroup\$ Why not calculate the 2014 code point and skip the -A flag? 23 bytes \$\endgroup\$ – Jo King Nov 1 '18 at 9:46
  • \$\begingroup\$ @JoKing Ah, didn't thought about that.. Thanks a lot for halving the byte-count! :) \$\endgroup\$ – Kevin Cruijssen Nov 1 '18 at 10:18
  • 1
    \$\begingroup\$ 22 bytes. How it actually works is a bit weird... \$\endgroup\$ – Jo King Nov 1 '18 at 10:26
  • \$\begingroup\$ @JoKing Oh, smart! That 23-byter was pretty obvious and I can't believe I missed it now. But that 22-byter is very smart and not something I would have thought of myself. Well done! It's only my first Lost answer, so hopefully I will get better at it. Btw, out of curiosity, is there a reason the language is lacking a divide and modulo operator? \$\endgroup\$ – Kevin Cruijssen Nov 1 '18 at 10:43
  • \$\begingroup\$ shrugs Minimalism? \$\endgroup\$ – Jo King Nov 1 '18 at 12:53
2
\$\begingroup\$

Rockstar, 34 32 bytes

X was up equalizing a word
Say X

Say hello to rockstar! (No I didn't make this one)

Explanation:

This first line:

X was up equalizing a word

Uses Rockstar's Poetic number literals. (As opposed to regular literals, which use numbers).

This means that the length of every word after was indicates the digit in that position. So here we have a 2 length (up), a 10 length (equalizing) a 1 length (a) and a 4 length (word). The length is % 10, so equalizing becomes a 0, and the result is that the variable X has the value 2014.

Then of course we print it with Shout

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

><>, 7 4 bytes

"nߞ

Try it online!

Explanation

"nߞ      : Put the string nߞ onto the stack.            Stack: [110, 2014]
 n       : Print the top item of the stack as a number. Stack: [110]
  ߞ      : Error out.
\$\endgroup\$
  • \$\begingroup\$ Huh, this worked really well in Runic too. One byte shorter than the solution I came up with a couple weeks ago. Not sure why I didn't try that before. \$\endgroup\$ – Draco18s Feb 6 at 2:30
2
\$\begingroup\$

Keg, 2 bytes

ߞ

Keg auto pushes any characters that aren't instructions to the stack, and ߞ has a unicode value of 2014, which then gets printed.

Try it Online!

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

maybe not the shortest, but one of the more readable ones in Smalltalk:

Transcript show: Date today year.
\$\endgroup\$
  • 6
    \$\begingroup\$ see the comments. You can't use current Year. \$\endgroup\$ – Wasi Jan 1 '14 at 19:27
  • \$\begingroup\$ This doesn't work.. (lol) \$\endgroup\$ – Albert Renshaw Jan 30 '17 at 3:36
1
\$\begingroup\$

ANSI C - 95 47 52 characters

#include <stdio.h>
main() { printf("%i", (('a' + 'a')/'a') * ('\a' + '\f') * ('<' - '\a') ); }

This program uses characters to initialise integers and multiplies: 2 * 19 * 53.

#include main(){printf("%i",'\aÞ');}

This program initialises an integer using charaterbytes and prints it. '\aÞ' is the bitpattern 00000111 11011110 this is also the bitpattern of 2014.


Disclaimer: this was made on a windows system with visual studio. This code depends on a lot of things, including - How your compiler endodes the characters you input. Þ has an ascii value of 222 (or its negative equivalent), this may vary depending on your system. The notation int a = 'abcd'; is in itself evil and depends on how memory is handled on your system - this includes endian issues. int a = '\0A'; a is 65 on my system but may be 16640 on your system.

main(){printf("%i",('C'-'A')*('T'-'A')*('v'-'A'));}

I went back to Version one and multiplied 2 * 19 * 53. This version uses only one byte at a time so it is endian compatible. Also it uses only characters in the range of [0 - 127] to be compatible to all systems.

\$\endgroup\$
  • \$\begingroup\$ You don't actually need to include stdio.h, most compilers will give a warning but include it for you. \$\endgroup\$ – nyuszika7h Jan 1 '14 at 21:58
  • \$\begingroup\$ This code yields 7 for me with tcc and 508830 with gcc. clang gives an error: character too large for enclosing character literal type. \$\endgroup\$ – nyuszika7h Jan 1 '14 at 22:02
  • \$\begingroup\$ @nyuszika7h ... 7 is equivalent with \a - this could be a problem with passing to the printf function, it would be interesting for me to see if int a = '\aÞ' is 2014 using tcc. 508830 looks very strange to me - i would guess some endian thing but n * 256 + 7 can never be that number. So this illuminates how string this code depends on the system. \$\endgroup\$ – Johannes Jan 1 '14 at 22:58
1
\$\begingroup\$

Solution 1

Octave/Matlab (55 chars)

a=pi;b=a*a;disp(ceil(a^a^a/a/a/a-b*b*a-a^a*b+b*b-b-b));

Solution 2

PHP (9 chars without tags, 12 with them Actually 2022 because of the new lines involved)

<!--Comment
  previous
  2013 lines -->
<?=__LINE__; <!-- This should be on line 2014 -->
\$\endgroup\$
  • \$\begingroup\$ That would be 2013 newlines followed by <?=__LINE__ for 2024 chars, not 9. \$\endgroup\$ – Peter Taylor Jan 2 '14 at 9:28
  • \$\begingroup\$ @PeterTaylor I didn't write 9 chars to win the challenge (since there are lots of shortest answers!), but because the actual code is that <?=__LINE__;?>, which I thought would be funny :) Nvm, I'll edit that. \$\endgroup\$ – Vereos Jan 2 '14 at 9:31
  • \$\begingroup\$ If it doesn't work without the newlines, they're part of the "actual code". \$\endgroup\$ – Peter Taylor Jan 2 '14 at 9:32
  • \$\begingroup\$ I guess you're right, edited. \$\endgroup\$ – Vereos Jan 2 '14 at 9:37
  • 1
    \$\begingroup\$ In PHP, you can skip ?> at end of the program. But interesting idea with __LINE__, even if it's ridiculous for such huge number. \$\endgroup\$ – Konrad Borowski Jan 2 '14 at 12:15
1
\$\begingroup\$

Game Maker Language, 22

show_message(ord("ߞ"))
\$\endgroup\$
1
\$\begingroup\$

C - 44 characters (85 with headers)

What, no one is abusing strings yet?

#include<stdio.h>
#include<netinet/in.h>
main(){printf("%u",ntohs(*(int*)"\a\xde"));}

Interestingly, this is a special case where neither character is printable, but their special code doesn't involve a number.

If we want no warnings, it needs to become 55 (96) characters:

#include<stdio.h>
#include<netinet/in.h>
int main(){return!printf("%u",ntohs(*(int*)"\a\xde"));}
\$\endgroup\$
1
\$\begingroup\$

Python, 14 characters

print ord('ߞ')

Short way ;)

\$\endgroup\$
  • \$\begingroup\$ Does it work without the u before the string? \$\endgroup\$ – Joe Z. Jan 7 '14 at 2:16
  • \$\begingroup\$ TypeError: ord() expected a character, but string of length 2 found \$\endgroup\$ – boothby Jan 7 '14 at 5:41
  • 1
    \$\begingroup\$ @JoeZ. this is valid Python 3 \$\endgroup\$ – Peter Gibson Jan 7 '14 at 6:21
  • 2
    \$\begingroup\$ In Python 3: SyntaxError: invalid syntax (Python 3 needs brackets around stuff being printed). \$\endgroup\$ – Joe Z. Jan 7 '14 at 7:41
1
\$\begingroup\$

C/C++ 39

main(){printf("%d%d",':'-'&',':'-',');}

ASCII for: ':' = 58, '&' = 38, ',' = 44. Using that, 58-38 = 20 and 58-44 = 14.

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

120 characters in Squeak Smalltalk trunk (4.5).
I did not search the shortest, but kind of graphical solution:

((Text string:'Happy\New year'withCRs attribute:TextEmphasis narrow)asMorph borderWidth:Float one+Float one)bounds area

It depends on font, margins, and so is quite fragile, but at least for me it worked.
In Squeak 4.4, it works with lowercase 'happy\new year'.

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

JavaScript, 49 Chars

A mathematical JavaScript version making use of only PI and E as source numbers.

(m=Math).pow(e=m.E,e*(p=~~m.PI))/m.sqrt(p)+e+e|""

... mmmm PIE.

Oh and just in case implicit returns are vetoed (56 Chars with alert):

alert((m=Math).pow(e=m.E,e*(p=~~m.PI))/m.sqrt(p)+e+e|"")
\$\endgroup\$
1
\$\begingroup\$

Clojure - 22

(apply *(map int"j#"))

(note: the # is ASCII character 19, Stack Overflow doesn't seem to like this but it's valid Clojure source...)

Clojure - 36

(dec(reduce +(nnext(range(int\@)))))
\$\endgroup\$
1
\$\begingroup\$

C++ - 63 bytes

I'm not sure if this method has been used, but I designed this myself anyway:

#include<iostream>
int main(){std::cout<<int('&'*(','+'\t'));}
\$\endgroup\$
  • \$\begingroup\$ You can use int instead of toascii for all of those to save a lot of characters. \$\endgroup\$ – Joe Z. Jan 7 '14 at 2:58
  • \$\begingroup\$ @JoeZ. OK, I didn't think of that. How can I calculate the bytes? \$\endgroup\$ – Hosch250 Jan 7 '14 at 2:59
  • \$\begingroup\$ Save your program as a text file, and then view how many bytes it is in the file manager. \$\endgroup\$ – Joe Z. Jan 7 '14 at 3:00
  • \$\begingroup\$ 2 is not allowed. \$\endgroup\$ – Danko Durbić Jan 7 '14 at 7:46
  • \$\begingroup\$ Oops, I'll fix that. \$\endgroup\$ – Hosch250 Jan 7 '14 at 16:08
1
\$\begingroup\$

Ruby 1.9, 10 bytes 

p 'ߞ'.ord
\$\endgroup\$
  • \$\begingroup\$ nice! 7 chars if you are in the irb command prompt 'ߞ'.ord \$\endgroup\$ – Eduard Florinescu Jan 8 '14 at 16:54
  • \$\begingroup\$ @EduardFlorinescu Thanks, I know. \$\endgroup\$ – Timtech Jan 8 '14 at 21:38
  • \$\begingroup\$ These are 8 bytes in UTF8. \$\endgroup\$ – schmijos Jul 24 '17 at 14:42

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.