Quine in Bytes, not Characters

1

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.

sugarfi

Posted 2019-11-01T23:42:56.023

Reputation: 1 239

Question was closed 2019-11-03T22:14:38.983

Does this have to meet standard Quine rules? For instance, 1 in Jelly is 1 byte long, and would output 1, is that acceptable? – caird coinheringaahing – 2019-11-02T00:24:29.443

@caird coinheringaahing - you do not have to follow standard rules. In this challenge, if it doesn't say you can't, assume you can. – sugarfi – 2019-11-02T01:11:05.017

When you say "byte count", do you mean UTF-8 byte count, or can we use our own encodings? For instance, if ¬ outputs 1, and is encoded as a single byte in our code page, would that be an acceptable answer? – caird coinheringaahing – 2019-11-02T01:14:32.990

No. A said in the answer, Unicode/UTF-8 byte counts are used. – sugarfi – 2019-11-02T01:30:02.253

3

Possible duplicate of Output your score

– Jo King – 2019-11-02T04:07:13.337

2Characters 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) – Jo King – 2019-11-02T04:10:20.880

2@JoKing pppery I would say this challenge is sufficiently different, given that the other is restricted-source. – Stephen – 2019-11-02T18:52:40.067

My biggest problem with calling this a duplicate is that my answer here meets this challenge. No way it meets the other challenge. It's not even possible. The same might be true for many, if not most, of the other answers here. That doesn't feel right somehow.... – ouflak – 2019-11-04T11:22:44.673

Answers

12

Most languages, 0 bytes

Try it online!

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

Jo King

Posted 2019-11-01T23:42:56.023

Reputation: 38 234

3Just realised that my Jelly answer could be golfed to this :/ I'll leave it to avoid duplicate answers though – caird coinheringaahing – 2019-11-02T05:14:09.143

1Not necessarily. In C it will be unable to find an entry symbol and the compile or link operation will fail. – rsonx – 2019-11-03T06:28:52.487

@rsonx Well yes, the empty program isn't valid in C... – Jo King – 2019-11-03T10:05:16.347

"If it is a function, it can output through its return value". This is not a function – JBernardo – 2019-11-03T11:22:57.790

1@JBernardo Yes? I never claimed it was a function. As stated, this is a full program that outputs via exit code. – Jo King – 2019-11-03T11:38:41.490

5

Python 2, 7 bytes

print 7

Try it online!

darrylyeo

Posted 2019-11-01T23:42:56.023

Reputation: 6 214

For Python 3, both print(8) and lambda:8 come out at 8 bytes. – boboquack – 2019-11-03T09:13:21.793

5

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. ‍⚕️

JosiahRyanW

Posted 2019-11-01T23:42:56.023

Reputation: 2 600

4

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

caird coinheringaahing

Posted 2019-11-01T23:42:56.023

Reputation: 13 702

Polyglot with Keg and Carrot obviously. – None – 2019-11-02T05:49:28.103

2@A_ And probably 05AB1E, Gaia, Deorst, or almost other golfing languages :P – caird coinheringaahing – 2019-11-02T05:59:58.813

It even works in PHP – Business Cat – 2019-11-03T03:49:19.033

4

Keg, 2 bytes

2#

Try it online!

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

79037662

Posted 2019-11-01T23:42:56.023

Reputation: 1 739

3

Perl 5 -p, 4 bytes

$_=4

Try it online!

Xcali

Posted 2019-11-01T23:42:56.023

Reputation: 7 671

3

Ruby, 3 bytes

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

p 3

Try it online!

Value Ink

Posted 2019-11-01T23:42:56.023

Reputation: 10 608

3

JavaScript, 4 bytes

Boring!

_=>4

Try it Online!

Shaggy

Posted 2019-11-01T23:42:56.023

Reputation: 24 623

2

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.

Neil

Posted 2019-11-01T23:42:56.023

Reputation: 95 035

2

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

Кирилл Малышев

Posted 2019-11-01T23:42:56.023

Reputation: 439

2

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.

Hactar

Posted 2019-11-01T23:42:56.023

Reputation: 646

1

Haskell, 5 bytes

f a=5

Try it online!

79037662

Posted 2019-11-01T23:42:56.023

Reputation: 1 739

Err... That's neither a function nor an action. Is this allowed? – Dannyu NDos – 2019-11-03T09:47:01.133

Not sure, changed it to be safe. – 79037662 – 2019-11-03T21:40:23.030

You could maybe argue that f=3 was a function that takes no arguments – Jo King – 2019-11-03T23:03:45.607

1

brainfuck, 20 bytes

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

Try it online!

79037662

Posted 2019-11-01T23:42:56.023

Reputation: 1 739

1

R, 6 bytes

cat(6)

Try it online!

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

Robin Ryder

Posted 2019-11-01T23:42:56.023

Reputation: 6 625

1

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.

user85052

Posted 2019-11-01T23:42:56.023

Reputation:

1

Bash, 6 bytes

echo 6

Try it online!

Delta

Posted 2019-11-01T23:42:56.023

Reputation: 543

1

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

AZTECCO

Posted 2019-11-01T23:42:56.023

Reputation: 2 441

1You 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. – Shaggy – 2019-11-03T03:32:08.393

@Shaggy yes.. I was just tempted to give my first 0bytes answer when I saw Jo King hint that most languages can do it – AZTECCO – 2019-11-03T08:10:50.813

1

Rust, 3 bytes

||3

Try it online!

betseg

Posted 2019-11-01T23:42:56.023

Reputation: 8 493

0

ouflak

Posted 2019-11-01T23:42:56.023

Reputation: 925

-1

PMD 85 BASIC, 0 bytes

Without any lines of code, RUN will respond with

OK

i.e. zero kilobytes.

(yes, it's cheating)

Radovan Garabík

Posted 2019-11-01T23:42:56.023

Reputation: 437