1
\$\begingroup\$

Introduction

A quine is a program that takes no input and produces a copy of its own source code as output. Writing a quine is a standard test of a programming language. Most quines operate using strings of characters: that is what the source code is made of, after all! However, this quine is slightly different.

Challenge

Your challenge is to write a program that takes no input and produces the number of bytes in the program as output.

  • By "takes no input", I mean does not change based on input. Your program can still take command line arguments, or even arguments from stdin, but it cannot do anything with them. It must either discard or ignore them. Basically, your program should produce the same output no matter what input is given.
  • Your program must output the number of bytes in it. If it is a function, it can output through its return value. If, and only if your language has no stdout, you may store output in a variable. The input can be printed as a string or an integer; the user cannot tell the difference between the output of print('5') or print(5)! Note that I said byte count, not character count. If your program uses Unicode characters that take up more than 1 byte (like some Jelly or APL programs), the output must reflect that.

Rules

This is so shortest answer in bytes wins! Edit: Actually, since there is a 1 byte answer, let's do top 3 shortest.

Edit: this question is not the same as Output your Score. For one, this one does not disallow cheating quines. Also, I do not require a trailing " bytes" in output.

\$\endgroup\$
8
  • \$\begingroup\$ Does this have to meet standard Quine rules? For instance, 1 in Jelly is 1 byte long, and would output 1, is that acceptable? \$\endgroup\$ Commented Nov 2, 2019 at 0:24
  • \$\begingroup\$ @caird coinheringaahing - you do not have to follow standard rules. In this challenge, if it doesn't say you can't, assume you can. \$\endgroup\$
    – sugarfi
    Commented Nov 2, 2019 at 1:11
  • 3
    \$\begingroup\$ Possible duplicate of Output your score \$\endgroup\$
    – Jo King
    Commented Nov 2, 2019 at 4:07
  • 2
    \$\begingroup\$ Characters in languages with SBCS do take up only one byte, so I don't see the point of penalising them for what character they use (which seems to be the opposite of what you want) \$\endgroup\$
    – Jo King
    Commented Nov 2, 2019 at 4:10
  • 2
    \$\begingroup\$ @JoKing pppery I would say this challenge is sufficiently different, given that the other is restricted-source. \$\endgroup\$
    – Stephen
    Commented Nov 2, 2019 at 18:52

20 Answers 20

12
\$\begingroup\$

Most languages, 0 bytes

Try it online!

Outputs via exit code, which is 0 for almost any language where an empty program is valid.

\$\endgroup\$
5
  • 3
    \$\begingroup\$ Just realised that my Jelly answer could be golfed to this :/ I'll leave it to avoid duplicate answers though \$\endgroup\$ Commented Nov 2, 2019 at 5:14
  • 1
    \$\begingroup\$ Not necessarily. In C it will be unable to find an entry symbol and the compile or link operation will fail. \$\endgroup\$
    – rsonx
    Commented Nov 3, 2019 at 6:28
  • \$\begingroup\$ @rsonx Well yes, the empty program isn't valid in C... \$\endgroup\$
    – Jo King
    Commented Nov 3, 2019 at 10:05
  • \$\begingroup\$ "If it is a function, it can output through its return value". This is not a function \$\endgroup\$
    – JBernardo
    Commented Nov 3, 2019 at 11:22
  • 1
    \$\begingroup\$ @JBernardo Yes? I never claimed it was a function. As stated, this is a full program that outputs via exit code. \$\endgroup\$
    – Jo King
    Commented Nov 3, 2019 at 11:38
5
\$\begingroup\$

Poetic, 87 86 bytes

-1 byte due to a slightly better representation of the character "8".

hey-o
i guess i got a number i can write
an apple a day keeps doctors away, we suppose

Try it online!

Poetic is an esolang I made in 2018 for a class project. It's basically brainfuck with word-lengths instead of symbols.

I couldn't resist making the word-lengths spell out a popular phrase, hehe. 🍎 👨‍⚕️

\$\endgroup\$
4
\$\begingroup\$

Jelly, 1 byte

1

Try it online!

This probably works in a lot of other languages as well. Note that the output does not have a trailing newline

\$\endgroup\$
3
  • \$\begingroup\$ Polyglot with Keg and Carrot obviously. \$\endgroup\$
    – user85052
    Commented Nov 2, 2019 at 5:49
  • 2
    \$\begingroup\$ @A_ And probably 05AB1E, Gaia, Deorst, or almost other golfing languages :P \$\endgroup\$ Commented Nov 2, 2019 at 5:59
  • \$\begingroup\$ It even works in PHP \$\endgroup\$ Commented Nov 3, 2019 at 3:49
4
\$\begingroup\$

Python 2, 7 bytes

print 7

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ For Python 3, both print(8) and lambda:8 come out at 8 bytes. \$\endgroup\$
    – boboquack
    Commented Nov 3, 2019 at 9:13
4
\$\begingroup\$

Keg, 2 bytes

2#

Try it online!

Not a duplicate, and this should hopefully clinch me 3rd place :)

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

Perl 5 -p, 4 bytes

$_=4

Try it online!

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

Ruby, 3 bytes

Probably one of the only times Ruby can beat Perl in bytes.

p 3

Try it online!

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

JavaScript, 4 bytes

Boring!

_=>4

Try it Online!

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

brainfuck, 20 bytes

-[>+<-----]>-.--.kek

Try it online!

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

Retina 0.8.2, 1 byte

^

Try it online! In Retina, the empty program outputs 1 more than the length of its input, which is bad here, since we don't want the output to depend on the input. Fortunately, either ^ or $ help here, as they force the output to be 1, which is conveniently also their length.

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

HQ9+, 1 byte

+

This language does not allow you to write a program that prints only one number. Therefore, I save the number of bytes in a special counter.

HQ9+ online interpreter

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

MathGolf, 1 byte

Try it online!

Explanation

╧  On the empty stack, pop a,b, push a.contains(b)
   0 definitely contains 0, pushing a 1.

Implicit output

MathGolf, 1 byte

)

Try it online!

Explanation

) Increment this 0 value on the stack, returning a 1.

MathGolf, 1 byte

=

Try it online!

Explanation

= Check equality of 0 and 0, returns 1.
\$\endgroup\$
0
2
\$\begingroup\$

Metatape, 22 bytes

@a{ooxooeooxoeo} !a !a

The space characters are not syntactically necessary, but they take up less space than it would to output 21 or 20.

@a{...} defines a subroutine named a, and !a executes that subroutine.

Output is bitwise (highest bit first). While the actual language is more complicated, for the sake of this program:

  • x makes subsequent os output 1.
  • e makes subsequent os output 0.
\$\endgroup\$
1
\$\begingroup\$

R, 6 bytes

cat(6)

Try it online!

(Note that Jo King's 0 byte answer is also valid in R.)

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

Bash, 6 bytes

echo 6

Try it online!

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

Rust, 3 bytes

||3

Try it online!

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

PMD 85 BASIC, 0 bytes

Without any lines of code, RUN will respond with

OK

i.e. zero kilobytes.

(yes, it's cheating)

\$\endgroup\$
1
  • \$\begingroup\$ I chuckled at this. \$\endgroup\$
    – ouflak
    Commented Jan 19, 2021 at 12:13
1
\$\begingroup\$

Japt -F0, 0 bytes

Try it

This can be my first 0 bytes answer!

Using -F"0" flag => outputs 0 if the programme returns a falsey value

\$\endgroup\$
2
  • 1
    \$\begingroup\$ You can golf that flag to -F0! But note, as it says in the docs, many will consider the -Ex & -Fx flags to be "cheating". This, though, I'd say is a more borderline case. \$\endgroup\$
    – Shaggy
    Commented Nov 3, 2019 at 3:32
  • \$\begingroup\$ @Shaggy yes.. I was just tempted to give my first 0bytes answer when I saw Jo King hint that most languages can do it \$\endgroup\$
    – AZTECCO
    Commented Nov 3, 2019 at 8:10
1
\$\begingroup\$

Haskell, 5 bytes

f a=5

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ Err... That's neither a function nor an action. Is this allowed? \$\endgroup\$ Commented Nov 3, 2019 at 9:47
  • \$\begingroup\$ Not sure, changed it to be safe. \$\endgroup\$
    – 79037662
    Commented Nov 3, 2019 at 21:40
  • \$\begingroup\$ You could maybe argue that f=3 was a function that takes no arguments \$\endgroup\$
    – Jo King
    Commented Nov 3, 2019 at 23:03
0
\$\begingroup\$

Turing Machine Code, 9 bytes

0 _ 9 * 1

Try it online!

\$\endgroup\$

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