628
\$\begingroup\$

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


It's 2017 2018 2019 2020 2021 2022 2023 2024 already, folks, go home.

Woo, 10 years of this challenge!

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

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

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


Leaderboard:

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

\$\endgroup\$
16
  • 24
    \$\begingroup\$ Even though numbers are ignored in brainfuck, I thought I'd post one anyway. 32 Chars: ++++++[>++++++++<-]>++.--.+.+++. \$\endgroup\$ Commented Apr 1, 2015 at 21:37
  • 7
    \$\begingroup\$ Brainfuck isn't a valid language for this challenge. \$\endgroup\$
    – Joe Z.
    Commented Apr 1, 2015 at 22:49
  • 14
    \$\begingroup\$ I know. That's why I posted it as a comment \$\endgroup\$ Commented Apr 1, 2015 at 22:51
  • 13
    \$\begingroup\$ I wonder if this question gets a small spike in popularity around New Year's. \$\endgroup\$
    – Joe Z.
    Commented Dec 26, 2015 at 23:28
  • 5
    \$\begingroup\$ Waiting for "Come on folks, don't you realize it's 2016?" :) \$\endgroup\$
    – padawan
    Commented Jan 4, 2016 at 23:35

333 Answers 333

1
3 4
5
6 7
12
3
\$\begingroup\$

Python 3, 27 bytes

I went through the effort of writing this script:

def to_base(n: int, b: int) -> str | None:
    if not 1 < b < 37:
        raise "Impossible base, try using a base between 1 and 37 (beginning and end not included)"

    if n == 0:
        return '0'

    possible_digs = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    res = []

    while n > 0:
        res += possible_digs[n % b]
        n //= b
    
    return ''.join(reversed(res))


def to_base_letters_only(n: int) -> str:
    bases_found = []
    for b in range(11, 37):
        c_n = to_base(n, b)
        digs_l_10 = False

        for d in c_n:
            if d in "0123456789":
                digs_l_10 = True
                break

        if not digs_l_10:
            bases_found.append([c_n, b])
    
    print(bases_found)

    if bases_found == []:
        return "No conversion found"
    return f"Conversion found: {(min_base := min(bases_found, key=lambda c: len(c[0])))[0]} in base {min_base[1]}"

print(to_base_letters_only(2014))

Which found BBC in base 13, which is 2014, without using arabic numerals.

So, my answer is this:

print(int("BBC",ord("\r")))

Try it online!

\r is Unicode 13.

Fun fact: This answer is 1 byte behind the Python 2 answer, because of print needing parentheses.

That script can also be used to find solutions for other numbers.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Normally we put the code first and the explanation afterwards \$\endgroup\$
    – mousetail
    Commented Jan 3, 2023 at 14:32
  • \$\begingroup\$ You could save a byte by switching to Python 2: print int("BBC",ord("\r")) \$\endgroup\$ Commented Jan 3, 2023 at 14:35
  • \$\begingroup\$ I already pointed out that. \$\endgroup\$
    – Joao-3
    Commented Jan 3, 2023 at 14:57
3
\$\begingroup\$

Python 3, 54 bytes

n=mp.dps=ord('㤃');print(str(mp.pi)[n-len('year'):n])

Try it online!

How it works

Extracts the year \$2024\$ beginning at the \$14591^{st}\$ digit of \$\pi\$

3.14...27617285830243559830032042024512072872535581195840...

The next 10 years that eventually appear in Pi's decimal expansion!

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

Commodore BASIC V2, tested on the Commodore C64, 37 PETSCII characters. Non-competing

Note that the {CRSR LEFT} in the following "source code" is the cursor left control character.

A=.↑.:A%=π+A:?A♥("╮")"{CRSR LEFT}"R╮(ST▂(A%),A)

Non-obfuscated, this would look like this:

A=.↑.:A%=π+A:PRINTASC("╮")"{CRSR LEFT}"RIGHT$(STR$(A%),A)

or on a Commodore C64 screen, it would look like this:

Commodore C64 answer to "Produce the number 2014 without any numbers in your source code"

\$\endgroup\$
5
  • 1
    \$\begingroup\$ What’s non-competing about this? Looks fine to me \$\endgroup\$ Commented Jan 12 at 19:02
  • \$\begingroup\$ So upvote it then? idk... \$\endgroup\$ Commented Mar 14 at 15:01
  • 1
    \$\begingroup\$ I didn’t upvote because I was (and still am) confused what you meant by non-competing, if that means the answer is invalid then why should I upvote it \$\endgroup\$ Commented Mar 14 at 15:53
  • \$\begingroup\$ It is not invalid, it is non-competing or just for fun/just for a laugh. \$\endgroup\$ Commented Mar 14 at 16:15
  • 2
    \$\begingroup\$ I guess I don’t get the joke \$\endgroup\$ Commented Mar 14 at 20:25
2
\$\begingroup\$

PHP (21 chars)

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

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

\$\endgroup\$
3
  • \$\begingroup\$ That looks like 19 characters to me. \$\endgroup\$
    – Joe Z.
    Commented Jan 2, 2014 at 15:06
  • 1
    \$\begingroup\$ (Oh wait, nonprintables.) \$\endgroup\$
    – Joe Z.
    Commented Jan 2, 2014 at 15:07
  • 1
    \$\begingroup\$ If it contains non-printables, you should provide a hex dump or list them. \$\endgroup\$
    – mbomb007
    Commented Mar 4, 2016 at 20:06
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\$
2
  • \$\begingroup\$ clever. 40 chars in PHP: $t=true;echo $t+$t.$t-$t.$t.$t+$t+$t+$t; \$\endgroup\$
    – zamnuts
    Commented Jan 5, 2014 at 10:08
  • \$\begingroup\$ Damn just wrote that while reading the answers well done, \$\endgroup\$
    – Noelkd
    Commented Jan 5, 2014 at 10:37
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\$
2
  • \$\begingroup\$ Shorter version using hexadecimal literals: print*,z'FBC'/len('hi');end. \$\endgroup\$ Commented Jan 8, 2014 at 12:31
  • \$\begingroup\$ @HristoIliev: Totally forgot about printing hex via z! Thanks a bunch! \$\endgroup\$
    – Kyle Kanos
    Commented Jan 8, 2014 at 14:51
2
\$\begingroup\$

Bash, 29 bytes

Bash without using external programs:

echo $((x=++y+y))$?$y$((x+x))
\$\endgroup\$
1
  • \$\begingroup\$ Reduce to 25 bytes by using: echo $[y=++x+x]$?$x$[y+y]. \$\endgroup\$
    – user92894
    Commented Aug 30, 2019 at 14:50
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
  • 2
    \$\begingroup\$ 12 chars: +/&" ~~~~h'"; 6 chars, 7 bytes, unicodey: `i$"ߞ" \$\endgroup\$
    – zgrep
    Commented Apr 13, 2017 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
  • 1
    \$\begingroup\$ You could shorten 'ߞ'n; to 'n;ߞ, I believe. \$\endgroup\$ Commented Nov 1, 2015 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\$
2
  • \$\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
    Commented Jun 6, 2014 at 3:36
  • \$\begingroup\$ @GlenO thanks! I added it as an edit. \$\endgroup\$
    – plannapus
    Commented Jun 6, 2014 at 7:15
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\$
2
  • 1
    \$\begingroup\$ It's 4 characters, yes, but 5 bytes. \$\endgroup\$
    – Joe Z.
    Commented Sep 20, 2014 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
    Commented Sep 21, 2014 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\$
2
  • \$\begingroup\$ That code doesn't work. Did you mean alert("ߞ".charCodeAt())? \$\endgroup\$ Commented Dec 27, 2014 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
    Commented Dec 27, 2014 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\$
2
  • 1
    \$\begingroup\$ I tested on Python 2.7, and it works fine there; so you can save one character. \$\endgroup\$
    – ProgramFOX
    Commented Jan 1, 2015 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\$ Commented Nov 4, 2015 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\$

T-SQL 27 bytes

PRINT ASCII('')*ASCII('j') 

Note that the character that isn't rendered here is the DC3 (CHAR(19)) in the first set of quote marks. It's unicode U+009F which, it would appear, doesn't copy and paste here too well but I can assure you it works in SQL Management Studio.

\$\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\$
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\$
2
  • 1
    \$\begingroup\$ Using the integer metagolfer in WheatWizard's brain-flak optimizer I found ((((((()()()()()){}){})){}{}()){()()({}[()])}{}()) which is 4 bytes shorter. \$\endgroup\$
    – 0 '
    Commented Dec 15, 2016 at 7:30
  • \$\begingroup\$ The challenge requires languages in which 0123456789 are valid tokens. Does Brain-Flak satisfy this requirement? \$\endgroup\$
    – Dennis
    Commented Jan 7, 2017 at 17:17
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\$
2
  • \$\begingroup\$ The challenge requires languages in which 0123456789 are valid tokens. Does Brain-Flak satisfy this requirement? \$\endgroup\$
    – Dennis
    Commented Jan 7, 2017 at 17:17
  • 2
    \$\begingroup\$ @Dennis yes @lt flags use decimal literals \$\endgroup\$
    – Wheat Wizard
    Commented Jan 7, 2017 at 21:59
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\$

Jelly, 3 bytes

⁽¥Æ

Try it online!

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

J, 21 bytes

,":,.$,:~}.,:,:'golf'

Try it online!

               'golf'  One dimensional array
           ,:,:        Itemize twice (1x1x4 array)
         }.            Drop first element (0x1x4)
      ,:~              Append to itself as distinct items (2x0x1x4)
     $                 Get dimensions (2 0 1 4)
   ,.                  Flatten items, essentially prints 2014 vertically.
                       (so there are no spaces)
,":                    To strings, flatten.    

20 bytes

#.(#_),,~(,~,~#_),%_
#.(#_),,~(,~$,._),%_

15 bytes

do'bbbc',~":_bd

11 bytes

,":_bk,:_be
\$\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\$
1
  • 2
    \$\begingroup\$ 6 bytes: eaa+n< \$\endgroup\$
    – Jo King
    Commented Apr 12, 2018 at 0:43
1
3 4
5
6 7
12

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