72
\$\begingroup\$

Challenge:

The concept is simple enough: write a full program to output its own code golf score!

Output should only be the byte count of your program and a trailing bytes.

BUT WAIT..... there is one restriction:

  • Your source code can not include any of the digits from your byte count
  • So if your score is 186 bytes, your program can not contain the characters 1 , 6 , or 8

Example Output:

315 bytes
27 Bytes
49 BYTES

Additional Rules:

  • Unnecessary characters, spaces, and newlines are forbidden in the source code, however trailing spaces and newlines are perfectly acceptable in output
  • There should be a single space between the number and bytes in the output
  • Letters are case insensitive
  • No self inspection or reading the source code
  • standard loopholes are disallowed

  • this is , so

Shortest code in bytes wins!

\$\endgroup\$
15
  • 6
    \$\begingroup\$ Does this need the quine tag, or may the code self-inspect? \$\endgroup\$
    – Adám
    Mar 29, 2018 at 15:59
  • 3
    \$\begingroup\$ @Dat, given the formatting of the word bytes I suspect the intention is that the count should include the bytes it takes to print the text: bytes \$\endgroup\$ Mar 29, 2018 at 16:16
  • 2
    \$\begingroup\$ Are leading spaces in output acceptable? \$\endgroup\$
    – rafa11111
    Mar 29, 2018 at 17:43
  • 5
    \$\begingroup\$ If my code is 1 byte long, should I output 1 bytes or 1 byte? (keep in mind there are already 41 answers, although I don't think any are affected) \$\endgroup\$ Mar 29, 2018 at 18:07
  • 2
    \$\begingroup\$ Can bytes be in any case pattern, e.g. bYtEs? \$\endgroup\$ Dec 27, 2019 at 14:56

183 Answers 183

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

C++, 52 bytes

[]{std::string a="41 bytes";a[0]++;a[1]++;return a;}

Try it online!

facepalm is it even competable? it just barely wins against BF! but still, no 5s and 2s in the code.

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

C, 31 bytes

main(){printf("%d bytes",'');}

Try It Online!

The unprintable character is the unit separator which value is 31.

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

naz, 48 44 bytes

2a2a2o2s2m8m1o2m2a1o9a9a5a1o5s1o9s6s1o9a5a1o

Explanation

2a2a2o   # Output "4" twice
2s2m8m1o # Output a space
2m2a1o   # Output "B"
9a9a5a1o # Output "Y"
5s1o     # Output "T"
9s6s1o   # Output "E"
9a5a1o   # Output "S"

Original 48-byte solution: 2a2a1o2a2a1o2m2m1o3m2a1o9a9a5a1o5s1o9s6s1o9a5a1o

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

Zsh, 16 bytes

<<<$[8*2]\ bytes

Try it online!

Heavily inspired by the Bash answer. <<< usually saves two bytes, but we lose one to escape a space.

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

x86-16 ASM, IBM PC DOS, 36 29 bytes

Listing:

        START: 
B0 1D       MOV  AL, SZ         ; get program size 
D4 0A       AAM                 ; BCD convert byte (AH=ones, AL=tens) 
86 E0       XCHG AH, AL         ; endian convert (AH=tens, AL=ones) 
50          PUSH AX             ; save AH = 9 
3030        ADD  AX, '00'       ; ASCII convert 
BF 0114     MOV  DI, OFFSET S   ; output string in DI 
8B D7       MOV  DX, DI         ; and output string in DX 
AB          STOSW               ; write digits to beginning of string 
58          POP  AX             ; restore AH = 9 (DOS write string function) 
CD 21       INT  21H            ; write to console 
C3          RET                 ; return to DOS
        S   DB '   bytes$'      ; output string buffer
        SZ  EQU LOW $-START     ; subtract starting address from ending address

Calculates the difference between the START memory address and the ending memory address. Then writes that value as decimal ASCII followed by the string ' bytes'.

There are no 0x02, 0x09, ASCII '2' (0x32) or ASCII '9' (0x39) in the code.

Output:

enter image description here

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

International Phonetic Esoteric Language, 13 bytes

" bytes"94suo

Explanation:

" bytes"      (push the string)
        94s   (push 13 by adding)
           uo (print twice)

Alternative (also 13 bytes):

" bytes"{D}uo (D == 13 base 36)
\$\endgroup\$
1
\$\begingroup\$

BRASCA, 13 bytes

Ln`setyb `[o]

Try it!

Explanation

Ln              - Output 13 as number
  `setyb `      - Push "bytes "
          [o]   - Output the rest of the stack
\$\endgroup\$
1
\$\begingroup\$

Nim, 17 bytes

echo 8+9," bytes"

Try it online!

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

Pxem, 11 bytes.

  • Filename: .n bytes.p
    • Escaped: \013.n bytes.p
  • Content: empty.

Try it online!

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

PEP8 Assembly, 50 bytes

STRO 4,d
STOP
.WORD 13616
.ASCII " BYTES"
.END

13616 is "50" in ASCII

A programming language made as an introduction to assembly and low-level concepts. Not sure I've seen it used here before, so might be a first?

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

Python 3, 34 bytes

print(f'{chr(51)}{chr(52)} bytes')

Try it online!

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

TI-Basic, 27 BYTES

Text(0,0,3*3²," BYTES

outputs on the graph. Text( allows to chain things to output, which Output( or Disp don't allow

there is probably room for improvement with one of those

  • 27 in 2 or 3 bytes is possible but useless (3^3, )
  • 26 in 3 bytes
  • 25 in 2 bytes ( not valid)
  • 24 in 1 byte ??

This solution should work on all TI-83 and 84. See also the 14 byte solution for the TI-84+ CE.

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

C, 50 49 46 28 bytes

m(){printf("%i bytes",' ');}

we need to tell the linker about our custom entry point and make sure stdio.h is included:

cc -o x x.c -e _m -include stdio.h

Notice, that the character in the printf statement is should not be a space but the ascii character for 28 (FS) in decimal. I am not able to edit the answer and add this.

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

Python 3, 22 19 bytes

print(22-3,'bytes')

Try it online!

Thanks to @twentysix for -3 bytes

\$\endgroup\$
1
  • \$\begingroup\$ 0b10110 to 22-3 gives 19 bytes: print(22-3,'bytes') \$\endgroup\$
    – twentysix
    Mar 16 at 18:01
1
\$\begingroup\$

Behaviour, 12 bytes

6+6+" bytes"

The output is implicit, but if we need explicit print, here's one for 13 bytes:

@6+7+" bytes"
\$\endgroup\$
1
\$\begingroup\$

GeoGebra, 13 12 bytes

Thanks Lince Assassino for -1 bytes

6+6+" bytes"

Pasting that into the GeoGebra calculator and pressing Enter gives the string 12 bytes.

\$\endgroup\$
2
  • \$\begingroup\$ 6+6+" bytes" would also work (exactly like my answer in another language) \$\endgroup\$ Mar 21 at 0:15
  • \$\begingroup\$ @LinceAssassino Lol thanks, can't believe I missed something as simple as that. \$\endgroup\$
    – Aiden Chow
    Mar 21 at 0:21
1
\$\begingroup\$

Aussie++, 35 bytes

G'DAY MATE!
GIMME ""+70/2+" bytes";

Tested in commit 9522366.


This was more annoying to golf than I thought it would be. At first I tried this (33 bytes):

G'DAY MATE!
GIMME 11+22+" bytes";

But for some bizarre reason, this prints out bytes33, not 33 bytes (see this github issue). So then I tried this (36 bytes):

G'DAY MATE!
GIMME ""+12+24+" bytes";

But that printed out 1224 bytes. I thought I could be clever and tried this (35 bytes):

G'DAY MATE!
GIMME ""+41-6+" bytes";

Only to be given the error THOSE AREN'T FUCKIN NUMBERS MATE!. It became apparent that I had to use parens if I wanted to use addition or subtraction.

However, parens aren't necessary for multiplication. I tried multiplication, but I reached an impasse: using 17*2 made it be 35 bytes but print 34, using 4*9 made it be 34 bytes but print 36, etc. I could use (4*9) to be 36 and print 36, but then I'd be breaking the rule on unnecessary characters (I think).

Only after considering using (9+28) for 37 bytes did the idea of division come to mind.

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

Befunge-93, 19 bytes

82*3+."setyb">:#,_@

Outputs 19 bytes.

Try it online!

Version with no numbers:

"D""/"-."setyb">:#,_@

Outputs 21 bytes.

Try it online!

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

Lexurgy, 15 bytes

a:
*=>15\ bytes
\$\endgroup\$
1
\$\begingroup\$

Minecraft Command Blocks, 198 bytes

A series of five command blocks with these commands:

scoreboard objectives add s dummy
scoreboard players set s s 33
scoreboard players set b s 6
scoreboard players operation s s *= b s
tellraw @a [{"score":{"name":"s","objective":"s"}},{"text":" bytes"}]

198 bytes

Pretty simple, it calculates 6 * 33 and prints the answer + bytes. I got lucky and didn't have to adjust the length of anything.

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

Knight, 17 bytes

O++''-8~9' bytes'

Try it online!

My second attempt at a second entry for the August 2022 language of the month event.

The original solution is left here for posterity

OUTPUT++''%60 36' bytes'
\$\endgroup\$
6
  • \$\begingroup\$ You mean August 2022 \$\endgroup\$
    – Steffan
    Aug 24 at 15:34
  • \$\begingroup\$ @steffan indeed I do. I'll fix that \$\endgroup\$
    – Benji
    Aug 24 at 15:42
  • \$\begingroup\$ The reason the ~3 isn't working is because the C implementation is out of date. You can use my interpreter here: knight-lang.netlify.app However, it's not quite correct as it outputs 22 bytes although it's 23 bytes. Should be easily fixable. \$\endgroup\$
    – Steffan
    Aug 24 at 16:10
  • \$\begingroup\$ Also, as you can find out by reading the spec, each function can be shortened to just its first letter. So OUTPUT is just O, but it would work the same if you did OSADKJKA or whatever. \$\endgroup\$
    – Steffan
    Aug 24 at 16:12
  • \$\begingroup\$ So here's 17 bytes: O++''+9 8' bytes'. Try it online! \$\endgroup\$
    – Steffan
    Aug 24 at 16:13
0
\$\begingroup\$

Attache, 18 bytes

Print[!4-6,$bytes]

Try it online!

This is simply printing !4-6 (which is factorial(4) - 6) followed by bytes.

\$\endgroup\$
0
\$\begingroup\$

Jotlin, 17 bytes

P("${8+9} bytes")

Uses the println builtin

\$\endgroup\$
0
0
\$\begingroup\$

Groovy, 22 bytes

{print"${0x16} bytes"}

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Pyt, 35 bytes

2⁵1⁺ᴇ⁻⁻1ᴇ⁺²2ᴇ4²+9⁺²⁺1ᴇ⁺²6-áƇǰ8Ḟ1+⇹ǰ

Try it online!

Explanation:

2⁵         Push 32
1⁺ᴇ⁻⁻      Push 98
1ᴇ⁺²       Push 121
2ᴇ4²+      Push 116
9⁺²⁺       Push 101
1ᴇ⁺²6-     Push 115
á          Convert stack to array, and push the array onto the stack
Ƈ          Cast to characters ([" ","b","y","t","e","s"])
ǰ          Join the elements of the array (" bytes")
8Ḟ1+       Push 35
⇹          Swap the top two elements on the stack
ǰ          Concatenate the stack as a string ("35 bytes")
           Implicit print
\$\endgroup\$
0
\$\begingroup\$

Swift, 22 bytes

print("\(18+4) bytes")

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Pip, 10 bytes

t." bytes"

Try it online!

Conveniently, there's a preset variable for the number 10.

\$\endgroup\$
0
\$\begingroup\$

Yabasic, 15 bytes

An anonymous answer that takes no input and outputs to STDOUT.

?7+8;
?" bytes"

Try it online!

\$\endgroup\$
0
\$\begingroup\$

uBASIC, 14 bytes

An anonymous answer.

0?2*7;" bytes"

Try it online!

\$\endgroup\$
0
\$\begingroup\$

MY-BASIC, 18 bytes

An anonymous MY-BASIC answer that outputs to STDOUT.

Print 9+9," bytes"

Try it online!

\$\endgroup\$
1
3 4
5
6 7

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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