56
\$\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\$
  • 6
    \$\begingroup\$ Does this need the quine tag, or may the code self-inspect? \$\endgroup\$ – Adám Mar 29 '18 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\$ – Jeff Schaller Mar 29 '18 at 16:16
  • 2
    \$\begingroup\$ Are leading spaces in output acceptable? \$\endgroup\$ – rafa11111 Mar 29 '18 at 17:43
  • 3
    \$\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\$ – Erik the Outgolfer Mar 29 '18 at 18:07
  • 1
    \$\begingroup\$ @JoKing well I didn’t address casing in the rules, but if somehow using capital letters makes your score lower, then by all means I’d love to see what you came up with. I say go for it! \$\endgroup\$ – X1M4L Mar 29 '18 at 22:50

155 Answers 155

1
\$\begingroup\$

Husk, 8 bytes

+sD4¨₆Ẏ¿

Try it online!

Explanation

+sD4¨₆Ẏ¿
    ¨₆Ẏ¿  Compressed string of " bytes"
  D4        Multiply 4 by 2
 s          Convert to string
+         Concatenate the strings
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Befunge-98 (FBBI), 12 bytes

"c.4k,@setyb

Try it online!

Thank you Jo King and Mistah Figgins for -3 bytes.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Attache, 19 bytes

Print&$bytes!STN!$t

Try it online!

Explanation

Print&$bytes!STN!$t
Print       !          print
     &$bytes           (with "bytes" as a right argument)
             STN!      convert string to number...
                 $t    "t" (corresponds to 19)

In sane syntax, this is: Print[STN["t"], "bytes"], which joins the arguments by spaces.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

vim, 12 bytes

a9 bytes<ESC>03<C-A>

<ESC> is 0x1b. <C-A> is 0x01

Try it online!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Cubix, 23 bytes

@"!w"SETYB"uUo<S;O'$.;

Try it online!

Cubified:

    @ "
    ! w
" S E T Y B " u
U o < S ; O  '
    $ .
    ; .

Watch it run

Failrly simple pushes SETYB onto the stack, pushes character 23 (ETB) and outputs as an integer. Push 32 (space) onto the stack then start outputting chars and popping until stack is empty.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

MBASIC, 17 bytes

6 PRINT 8+9"bytes

MBASIC requires line numbers; "6" doesn't appear in the output either. Turns out that the trailing quote is optional.

Output:

RUN
 17 bytes
Ok
| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ Byte count is calculated from the source code, not the RAM it takes up. So this should be 18 bytes. But +1 for using an uncommon language; we need more variety around here. \$\endgroup\$ – Ray Sep 27 '18 at 18:23
  • 1
    \$\begingroup\$ Even with a tokenizing interpreter? \$\endgroup\$ – wooshinyobject Sep 27 '18 at 19:08
  • \$\begingroup\$ Yes. If the size of the target language/object code/internal representation mattered, the score would change every time improvements were made to the implementation's optimizer. And there would be a lot of situations where making the source code larger would make the target code smaller, and vice versa, since optimizers work better when they have a lot of explicit information about what assumptions are safe to make. \$\endgroup\$ – Ray Sep 28 '18 at 1:58
1
\$\begingroup\$

Pascal (FPC), 29 bytes

begin write($1D,' bytes')end.

Try it online!

$1D is a hexadecimal constant. I'm glad Pascal has something shorter than other languages!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Python 3, 18 bytes

print(9*2,'bytes')

Try it online!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

k (oK), 16 bytes

Try it online!

($:4*4)," bytes"

String result of 4*4 and concatenate

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Chevron, 12 bytes

^n<<3*4
>^n

This is a fairly new language of my own creation - prototype interpreter, documentation, and example programs can be found at https://github.com/superloach/chevron.

Explanation:

  • ^n<<3*4 - calculate 3*4, store as n
  • >^n - output n
  • nothing else - implicit exit
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Deadfish~, 59 bytes

iisioiiiioii{ii}icii{iii}iic{ii}iiicdddddc{d}dddddc{i}iiiic

Try it online!

| improve this answer | |
\$\endgroup\$
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.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

C, 31 bytes

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

Try It Online!

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

| improve this answer | |
\$\endgroup\$
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

| improve this answer | |
\$\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.

| improve this answer | |
\$\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

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

C# (Mono C# Shell), 27 bytes

Console.Write(3*9+" bytes")

Try it online!

| improve this answer | |
\$\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)
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Golfscript, 12 bytes

6 6+" bytes"

Try it online!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Perl 5 + -Mfeature+say, 14 bytes

Relies on a generated program, so TIO link is to Bash which generates the program from xxd output. Uses -Mfeature+say instead of -M5.10.0 although I don't think it matters that much...

say~"ÎËß"

Try it online!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Javascript, 15 bytes

j=>0xf+' bytes'

Seems like the obvious answer.

Alternative:

j=>9+6+' bytes'

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Pyramid Scheme, 477 bytes

   ^      ^      ^      ^      ^      ^
  / \    / \    / \    / \    / \    / \
 /out\  /out\  /out\  /out\  /out\  /out\
^-----^ -----^ -----^ -----^ -----^ -----^
-^   / \    / \    / \    / \    / \    / \
 -^ /chr\  /chr\  /chr\  /chr\  /chr\  /chr\
 /*\-----^ -----^ -----^ -----^ -----^ -----^
^---^    -^    / \    / \    / \    / \    / \
-^  -^   / \  /98 \  /121\  /116\  /101\  /115\
/9\ / \ /32 \ -----  -----  -----  -----  -----
---/   \-----
  /  53 \
  -------

Try it online!

Outputs 477 bytes by multiplying 9 by 53.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Wouldn't that violate the rule against unnecessary whitespace? Or maybe I don't understand? \$\endgroup\$ – Steve Bennett Jun 24 at 1:54
  • \$\begingroup\$ @SteveBennett You're right. I've modified it so that the program doesn't have redundant characters (though it can be golfed pretty easily \$\endgroup\$ – Jo King Jun 25 at 12:30
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.

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Jotlin, 17 bytes

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

Uses the println builtin

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Groovy, 22 bytes

{print"${0x16} bytes"}

Try it online!

| improve this answer | |
\$\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
| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Swift, 22 bytes

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

Try it online!

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Pip, 10 bytes

t." bytes"

Try it online!

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

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Yabasic, 15 bytes

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

?7+8;
?" bytes"

Try it online!

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

uBASIC, 14 bytes

An anonymous answer.

0?2*7;" bytes"

Try it online!

| improve this answer | |
\$\endgroup\$

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.