Produce the number 2014 without any numbers in your source code

  • 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 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>

    Even though numbers are ignored in brainfuck, I thought I'd post one anyway. 32 Chars: `++++++[>++++++++<-]>++.--.+.+++.`

    Brainfuck isn't a valid language for this challenge.

    I know. That's why I posted it as a comment

    I wonder if this question gets a small spike in popularity around New Year's.

    Waiting for "Come on folks, don't you realize it's 2016?" :)

    @cagirici Done.

    @BradenBest It's possible to do it in 31 characters in at least two different ways: +++++++[>+++++++<-]>+.--.+.+++. and ++++++++++[>+++++<-]>.--.+.+++.

    @JoeZ. It's almost that time of the year again.

    possible to do the brainfuck answer in 23 bytes `-[>+<-----]>-.--.+.+++.`

    That language is full of language!

    `(unsigned char)'\xca'*'\xa'` for 2020 in C.

  • cat

    cat Correct answer

    5 years ago

    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.

    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!

    I just discovered this language today and I already love it. However, it's not purely esoteric, which makes it even better!

    BTW: this does the same thing as CJam's `KE`, but is actually valid because it's a language from before 2014.

    The smug look on my face right now resembles that of a Fortran-77 wizard after beating some proponent of Python in a [tag:fastest-code].

    Also this solution will work until 2025 at least, until you pass U!Z!.

    But by then, somebody will invent a language that prints out the Unicode value of any unrecognized token, and then the high score will be at 2 bytes forevermore.

    This a game of @cat and Mouse-2002.

    @DigitalTrauma indeed :3

    Running the 2007 binary using Wine on Ubuntu, the program as written produces an error message to the standard output which doesn't include the string `2014`. The modified program `U!O!$` works, producing `2014` and no trailing newline.

    @JoeZ, that's... that's kinda what I've done. ;)

  • Python, 52 bytes

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

    Updated for 2015 thanks to @Frg:

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

    Mouse over to see 2016 version:

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

    Try it online!

    You deserve the cleverness award

    You forgot a `print` somewhere. Nice one otherwise :)

    wow - this is so in the spirit of this question. <3

    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.

    Is this a rip-off of Mikael Mayer's answer in Scala, though?

    No, I did not look at anyone else's answers first.

    I only posted mine two hours before yours. This one is not that hard to find by oneself.

    Ugh, ever since I started programming in Befunge, Python looks so wordy. But since this is such an amazing solution (+1), here is the equivalent Befunge: `"Happy new year to you!"[email protected]`

    You want terse? Ruby: `p 'Happy new year to you!'.sum`

    `print sum(ord(c) for c in 'HAPPY NEW YEAR To you too.')` Oh wait, I'm a year late. That's 2013.

    `sum(map(ord,'Happy new year to you!'))` would save 7 characters.

    Even at my best I am a bogey golfer.

    I created this account just to give +1!

    `sum(b'Happy new year to you!')` in Python 3

    `sum(bytearray('Happy new year to you!'))` in Python 2.6+

    Awesome timing for awesome answer!

    haha good answer, in PHP : `echo array_sum(array_map('ord',str_split('Happy new year to you!')));`

    You guys made my day! Thank you and have a great year wherever you are :)

    Printable ASCII at 32-127 means about max 62 chars, min 15. You clocked 22. I'd like to see your list of things you considered before picking this one, added to the answer. If it's code golf, how much smaller while being literate could it get...margin is 7 chars. :-)

    It's hard to remember exactly, but the first thing I tried was "Happy new year!", then "Happy new year!!!!!", then "Happy new year everyone!", and finally 'Happy new year to you!'

    Mind blown! That is very clever of you sir!

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

    Uh....I get invalid syntax in 3.4? How does one run this?

    For Python 3.x, print needs ( )'s around the expression.

    Congrats on being the first answer on this site to reach 1,000 upvotes. :)

    You don't need the space after `ord(c)`

    `print sum(ord(c) for c in 'Happy New Year to You!!!!')` for 2017 :D

    Why were revisions undone for `print sum(map(ord,'A Happy New Year to You!'))`? It does the same thing.

    @SunnyPatel it's frowned upon to edit in golfs

    When can haz 2017?

    @Phoenix `print sum(ord(c) for c in 'Happy New Year to You!!!!')`

    @dansalmo Perhaps you want to add that one to the answer as well? Would be cool to see the entire list in 2025. ;) (Oh, and I took the liberty to add a TIO-link.)

    @KevinCruijssen That wasn't their solution. fedorqui posted that solution nearly a year prior, up a few comments.

    Exactly 1234 upvotes at the time of the posting of this comment.

    One byte can be saved by deleting whitespace before "for".

    @stackzebra and also by deleting whitespace after `in`

    I offer: `print(ord('&')*ord('j')/len('NY'))`

    This does not make a serious attempt at solving the question (this is code-golf)

    ```print(ord('ߞ'))``` for -36 bytes.

    `print(sum(ord(c) for c in 'have a happy new year!!'))`

  • Befunge 98 - 17 11 9 8 bytes

    '-:*[email protected]
    

    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
    [email protected]   prints the result, then ends the program
    

    Interestingly, 452-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)

    [email protected]
    

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

    "ߞ"[email protected]
    

    Old version

    cdd**[email protected]
    

    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`[email protected]+,;
    

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

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

    Wouldn't `a:[email protected]` achieve the same? Saves a character by printing 20 and then 14.

    @MSalters That would actually print `20 14`

    @Quincunx Where does it say that isn't allowed?

    @11684 The output is rather well defined in the question. If a program printed: `randomstuff2randomstuff0randomstuff1randomstuff4` I wouldn't consider it a valid solution.

    I agree. But at least in my native language (Dutch) spaces can be used in numbers to make numbers more readable. So I wouldn't categorise a space as 'random stuff'.

    @Plato Rather than read the wikipedia article (which only includes Befunge 93), if you want to learn about Befunge 98, read the official specs

    By the same idea, `'&:f+*[email protected]` should work as well.

    @MvG yeah, I was just manually searching for short solutions, then wrote a program, then tried different methods with that program. Of course there are other short methods.

    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?

    Can I edit the question to include my answer?

  • 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!
    

    `Happy = Time; Happy.new.year`

  • 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 '—'
    

    That's very clever, but the question requests a program that prints the number.

    If printed error codes count, this submission should win.

    +1. The question doesn't say, "prints **only** the number and nothing else".

    I don't care if its valid or not, it's pretty awesome.

    I joined this community just to like this post.

  • Python, 26

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

    bbc is 2014 in base 13

    Would've been my approach. Until I saw the accepted answer...

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

    13 years ago. RIP.

    IMO, this answer is in "True Pythonese"

    Wikipedia reference for the Douglas Adams and base-13, http://en.wikipedia.org/wiki/Base_13

    @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`.

    Coincidence? I think not! :-)

    Woah I almost upvoted your `bbc is 2014 in base 13` but then I realized it has 42 upvotes. Perfection

    Here is a permalink to Base 13 as of Jan 4 '14 for anyone interested. Be wary that it contains a mild spoiler to "The Restaurant at the End of the Universe".

  • 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
    

    ``\let~\number~`^^T~`^^N\bye`` 25 chars/bytes. You IMHO count wrong, it's 25 for your solution as well.

    @tohecz I think both our solutions are actually 26-byte long.

    If the current year is wanted, then 13 bytes: `\the\year\bye`

    `+'ߞ'` also works in Scala (and a few other languages I imagine)

  • dc, 6 chars

    DiBBCp
    
    • 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
    

    True, but the actual dc program is still `DiBBCp` (6 chars), the rest is just a way to run it.

    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 ;-) http://en.wikipedia.org/wiki/Base_13. I am upvoting @daniero's comment instead and leave the answer with this magnificent 42 reputation ;-)

    @PabloMarin-Garcia, unfortunatelly some unaware person broke it... Has 43 votes now. Please go back and downvote! :)

    @Tomas Vogons always the Vogons. Resistance is futile against the intergalactic burocracy.

    I cannot even find the `D` command in the man page. What does it do? Never mind... D is hex for 13.

    I would upvote but you have 64 votes

    @mpapis Or `dc -eDiBBCp`. Same length, I think.

  • Morse Code, 23

    ;)

    ..--- ----- .---- ....-
    

    "in any language in which numbers are valid tokens"

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

    No, the question said that numbers have to be valid in the language you're using. `.` and `-` aren't numbers.

    @Doorknob — David is right.

    Braille could be shorter :)

    Good point. Btw, I was relieved that no one asked how I get Morse Code to run on my computer.

    @DavidCarraher What do you mean? I naturally assumed you used this repo to decode it. https://github.com/Nyubis/mspa-morse-decoder Everyone's doing it...

    @MichaelCalkins Of course. How silly of me.

    This isn't compiling for me...

    I claim this language isn't Turing-complete.

    @JoeZ. I claim this language is not even a programming language.

    @SuperJedi224 I claim that non-languages are now allowed on CGCC.

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


    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.

    o=!"";(o+o)+""+(o-o)+(o+o-o)+(o+o+o+o)

    25 bytes: alert('ߞ'.charCodeAt())

    +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**[email protected]` (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.

    This wasn't the first answer to not use character codes; I have several earlier ones.

    @Quincunx: you're right; skimming through I didn't catch that your version was using hex digits, not character codes.

    `o=+!'';t=o+o;''+t+(+!o)+o+(t+t)`, a bit smaller than @kernel-james one

    R code with 38 characters `x=T+T;y=x*x;x+floor(exp(pi)^x)*y-y^y/x`

    Nice catch, @djhurio.

    I also like @KernelJames version (and Ricardo's improvement) though they really qualify as a completely different method rather than an improvement on mine -- I assume the "protected" status wasn't letting you post?

    two k implementations of this algo, both 39 chars: 1: ```-_-(x*p*p:exp [email protected]#`)-f*x*x*x:f*f:#`` ```; 2: ```f+(x*_p*p:exp [email protected]#`)-f*x*x*x:f*f:#`` ```. I can't seem to squeeze it any further at the moment....

    and here it is in APL in 31 chars (which i'm quite new to, so i'm sure it can be improved--particularly the hacky generation of the `2` constant): `⌈(x×p×p)-f×x×x×x←f×f←⍴⍕⌊p←*○~⊃⍬`

License under CC-BY-SA with attribution


Content dated before 6/26/2020 9:53 AM