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
  • 7
    \$\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

184 Answers 184

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

SmileBASIC, 12 bytes

?3*4;" bytes

(Probably works in a bunch of other BASIC dialects, too)

Alternatives:

?&HC;" bytes
?9+3;" bytes
\$\endgroup\$
1
\$\begingroup\$

jamal, 14 characters

{@* 2 7} bytes

Sample run:

bash-4.4$ perl jamal.pl ownsize.jam 
14 bytes
\$\endgroup\$
1
\$\begingroup\$

Fortran (GFortran), 24 bytes

PRINT*,11+13,'BYTES'
END

Try it online!

Outputs "24 BYTES" with some leading spaces, because, you know, it's Fortran... you can't tell him to do something and expect that he will do exactly as you said, specially if it involves strings :)

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

PowerShell, 14 bytes

"$(2*7) bytes"

Try it online!

Ho-hum. Uses an inline code block $(...) to put 14 into the string before leaving it on the pipeline. Output is implicit.

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

TeX, 16 bytes

^^q^^v bytes\bye
\$\endgroup\$
1
\$\begingroup\$

Ruby, 15 bytes

p"#{0xf} bytes"

Try it online!

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

Foo, 13 bytes

&9+4$i" bytes

Try it online!

Explanation

&9+4$i" bytes
&9              push 9
  +4            add 4 (13)
    $i          output as integer
      " bytes   print out " bytes"

14 bytes

@20&$h" bytes"

Same general idea, but (ab)uses hexadecimal printing.

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

Pyth, 11 bytes

+hT" bytes"

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ Why do you have h? Doesn't that just add the eleventh byte that it's there to account for, and it can thus be removed safely? \$\endgroup\$
    – Steven H.
    Apr 10, 2018 at 22:21
1
\$\begingroup\$

Python 2, 18 17 bytes

print 8+9,'bytes'

-1 byte thanks to @Wondercricket.

Try it online.

\$\endgroup\$
2
  • \$\begingroup\$ That trailing space is not in the output, I think it's still precisely what the rule is intended to forbid. However, you can use parentheses around 2*9 instead. \$\endgroup\$ Mar 30, 2018 at 0:48
  • \$\begingroup\$ @ØrjanJohansen I changed it to 8+9 instead to save a byte. :) \$\endgroup\$ Mar 30, 2018 at 6:58
1
\$\begingroup\$

Rust, 34 bytes

fn main(){print!("{} bytes",17*2)}

Try it online!

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

C# (Visual C# Interactive Compiler), 20 bytes

Write(11+9+" bytes")

Try it online!

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

Excel, 13 bytes

=6+7&" bytes"

Output: 13 bytes

Nothing fancy. It's different from the other Excel answers as those are both based in VBA. This formula version is longer.

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

T-SQL, 32 bytes

print char(51)+char(50)+' bytes'

Best I could come up with.

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

Javascript,26 bytes

console.log(78/3+" bytes")

Try it online!

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

Octave, 42 bytes

I figured I'd try a more interesting approach that's Octave-specific (and only works on some platforms).

printf('%i bytes',printf('%c',8+~(10:51)))

Note: This doesn't work on TIO or Octave-online.net, but it does work on Octave 4.2.0 on my laptop.

Explanation:

printf('%i bytes',... ) specifies that we will print a string starting with an integer %i followed by the characters ' bytes'. The second part of the first printf-function call is another call to printf('%c',...). When printf is called with an output argument, it returns the number of characters in the output string, as well as the string. The second part of the second printf call is 8+~(10:51). This is a shorter way to write [8, 8, 8 ...] 42 times. 8 is the ASCII-value of the backspace. The string to be printed is therefore 42 backspaces. This doesn't show when typing it in the terminal, so we'll get 42 bytes without a trailing newline:

enter image description here

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

MySQL, 28 bytes

SELECT CONCAT(7*4,' bytes');
\$\endgroup\$
1
\$\begingroup\$

Tcl, 23 bytes

puts [scan  %c]\ bytes

Try it online!


Tcl, 23 bytes

puts [expr 19+4]\ bytes

Try it online!

\$\endgroup\$
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
\$\endgroup\$
1
\$\begingroup\$

Befunge-98 (FBBI), 12 bytes

"c.4k,@setyb

Try it online!

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

\$\endgroup\$
2
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.

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

Pepe, 74 bytes

rEeEeeEeEereEEreeeEeeeeereeEEeeeEereeEEEEeeEreeEEEeEeereeEEeeEeEreeEEEeeEE

Try it online!

It's a boring answer, rEeEeeEeEereEE pushes 74 into stack r and outputs the number, and the rest of the code prints bytes

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

Python (REPL), 16 bytes

'%d bytes'%(8*2)

Output :

16 bytes
\$\endgroup\$
2
  • 7
    \$\begingroup\$ You could use f-strings like f'{7*2} bytes' \$\endgroup\$
    – Jo King
    Sep 27, 2018 at 14:34
  • \$\begingroup\$ Or, if you insist on using an older version of Python, you could use raw string r'%d bytes'%14 \$\endgroup\$
    – mypetlion
    Sep 27, 2018 at 16:04
1
\$\begingroup\$

vim, 12 bytes

a9 bytes<ESC>03<C-A>

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

Try it online!

\$\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.

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

LOLCODE, 66 bytes

Just because it's funny

HAI 1.2,VISIBLE SMOOSH PRODUKT OF 2 AN 33 AN " bytes" MKAY,KTHXBYE

Output

66 bytes

\$\endgroup\$
1
  • \$\begingroup\$ +1 because it's funny \$\endgroup\$
    – CreaZyp154
    Mar 21, 2022 at 9:25
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
\$\endgroup\$
3
  • 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, 2018 at 18:23
  • 1
    \$\begingroup\$ Even with a tokenizing interpreter? \$\endgroup\$ Sep 27, 2018 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, 2018 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!

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

k (oK), 16 bytes

Try it online!

($:4*4)," bytes"

String result of 4*4 and concatenate

\$\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
\$\endgroup\$
1
\$\begingroup\$

Deadfish~, 59 bytes

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

Try it online!

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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