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
2
3 4 5
7
4
\$\begingroup\$

Hexagony, 26 22 Bytes

B{3'/bs.<t>;ey;:!$@P0/

-4 Bytes @Jo King

Try it online!


More Readable:

   B { 3 '
  / b s . <
 t > ; e y ;
: ! $ @ P 0 /
 . . . . . .
  . . . . .
   . . . .

Reuses every semicolon twice similar to this answer.

\$\endgroup\$
1
  • \$\begingroup\$ It even uses one of the semi-colons 4 times! \$\endgroup\$
    – Jo King
    Sep 28, 2018 at 11:20
4
\$\begingroup\$

Forth (gforth), 14 13 bytes

$d . ." bytes

Try it online!

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

Red, 43 bytes

print[to-integer 8.6 * length? b: "bytes"b]
\$\endgroup\$
1
3
\$\begingroup\$

><>, 13 bytes

#o<" bytes"nd

Try it online!

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

Batch, 32 bytes

@@echo %COMSPEC:~-10,-010% bytes

COMSPEC is usually %WINDIR%\system32\cmd.exe so I extract the substring from 10 to 8 characters from the end. Old 16-byte self-referencing version:

@echo %~z0 bytes

Fortunately the byte count wasn't a multiple of 10.

\$\endgroup\$
1
  • \$\begingroup\$ @manatwork OK, I hadn't seen that, here's a new version. \$\endgroup\$
    – Neil
    Mar 29, 2018 at 21:16
3
\$\begingroup\$

JavaScript, 16 15 bytes

x=>0xf+' bytes'
\$\endgroup\$
4
  • \$\begingroup\$ _=>5*3+' bytes' \$\endgroup\$
    – Neil
    Mar 29, 2018 at 19:36
  • 1
    \$\begingroup\$ @Neil Both the code and the byte-count contains a 5 in that case.. \$\endgroup\$ Mar 29, 2018 at 20:04
  • \$\begingroup\$ @KevinCruijssen Bah, I can't believe I overlooked that. \$\endgroup\$
    – Neil
    Mar 29, 2018 at 21:17
  • \$\begingroup\$ Submissions are required to be full programs "write a full program to output its own code golf score!" \$\endgroup\$
    – user41805
    Apr 15, 2018 at 12:55
3
\$\begingroup\$

7Zip - 90 14 bytes

Hex dump:

00 75 0d 08 c0 00 0d 08 03 00 00 03 04 1d  

To use:

save into a source file, named anything.

run the compiler from the command line: 7z e [source name]

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

Excel VBA, 10 bytes

An anonymous VBE immediate window function that takes no input and outputs to the vbe immediate window.

?2*5"bytes

Output

10 bytes
\$\endgroup\$
2
  • \$\begingroup\$ My Excel shows additional leading space. Is it allowed? \$\endgroup\$
    – pajonk
    Mar 30, 2018 at 9:04
  • \$\begingroup\$ @pajonk That is the default nature VBA's Print and ? statement when handling number types, and is generally accepted to be valid for PPCG. That said, it may the space may be forcefully removed by converting to a string, and then operating upon that string, such as ?6+7&&" bytes for 13 bytes. \$\endgroup\$ Mar 30, 2018 at 17:28
3
\$\begingroup\$

Jstx, 4 bytes

♦─]P

Try it online!

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

C++ (GCC), 51 bytes

Thanks to @ceilingcat!

#import<iostream>
main(){std::cout<<063<<" bytes";}

Try it online!

C++ (GCC), 56 bytes

#import<iostream>
main(){std::cout<<(int)'8'<<" bytes";}

Try it online!

More portable version (60 bytes):

#import<iostream>
int main(){std::cout<<(int)'<'<<" bytes";}

#import is not standard C++, but should work at least with GCC, Clang, and MSVC.

Try it online!

Standard compliant version (61 bytes):

#include<iostream>
int main(){std::cout<<(int)'='<<" bytes";}

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ Suggest 063 for (int)'8', 067 for (int)'<' and 070 for (int)'=' \$\endgroup\$
    – ceilingcat
    Apr 1, 2018 at 0:09
3
\$\begingroup\$

m4, 15 bytes

As in the m4 POSIX macro processor.

eval(8+7) bytes
\$\endgroup\$
3
\$\begingroup\$

Mathematica frontend, 18 bytes (maybe 10?)

Row@{2*9," bytes"}

Thanks to @ovs

A naughty way ... as I don't know whether this counts (10)

2" bytes"5

Well it depends on how you define space.

enter image description here

Wolfram Language (Mathematica), solution w/o frontend (30)

Print[ToString[5*6]<>" bytes"]

Try it online!

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

TI-Basic (TI-84 Plus CE with OS 5.2+), 14 bytes

toString(9+5)+" BYTES

toString( is a two-byte token, all other characters used are one-byte tokens.

toString( can be replaced with eval( for the same output and score.

Explanation:

  • toString(9+5) Returns the string "14"

  • +" BYTES Adds the string " BYTES", to get "14 BYTES"

  • TI-Basic implicitly returns/prints the last item evaluated, so 13 BYTES is output.

\$\endgroup\$
2
  • \$\begingroup\$ What calculator has a toString( function? \$\endgroup\$
    – kamoroso94
    Apr 9, 2018 at 10:05
  • 1
    \$\begingroup\$ @kamoroso94 The TI-84 Plus CE. Source \$\endgroup\$ Apr 9, 2018 at 15:06
3
\$\begingroup\$

MathGolf, 9 bytes

G½ "bytes

Try it online!

Explanation

Quite simple really

G            Push 18
 ½           Halve the result, giving 9
             Push a space character
   "bytes    Push "bytes"
\$\endgroup\$
3
\$\begingroup\$

Python 2, 17 bytes

print 9+8,'bytes'

Output: 17 bytes

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

Bash, 20 18 17 bytes

echo $[8+9] bytes

Try it online!

-2 bytes thanks to @manatwork.
-1 byte thanks to @boboquack.

\$\endgroup\$
6
  • \$\begingroup\$ echo $[20-2] bytes for 18 bytes? \$\endgroup\$
    – manatwork
    Mar 29, 2018 at 17:20
  • \$\begingroup\$ @manatwork woah, I didn't know bash could do math like that \$\endgroup\$
    – Maya
    Mar 30, 2018 at 8:32
  • \$\begingroup\$ “The old format $[expression] is deprecated and will be removed in upcoming versions of bash.” — man bash. But in meantime we enjoy using it here in PPCG. \$\endgroup\$
    – manatwork
    Mar 30, 2018 at 8:37
  • 2
    \$\begingroup\$ echo $[5#33] bytes also works for a score of 18. \$\endgroup\$ Mar 30, 2018 at 17:40
  • 1
    \$\begingroup\$ Doesn’t 8+9 work for 17? \$\endgroup\$
    – boboquack
    Jul 30, 2019 at 6:01
3
\$\begingroup\$

C# (Mono C# Shell), 27 bytes

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

Try it online!

\$\endgroup\$
3
\$\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!

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

Brain-Flak, 90 bYTES

((((((<>))))[])[]([]((((([][][]))))([{}]()([]({}{}){}{}<>)))))(([][])[()]((([]{}))({}{})))

Try it online!

It took a while but I got us down to double digits.

I stole a technique of pushing a bunch of zeros in order to abuse [] from JoKing's answer. However I have modified it a bit.

Instead of pushing zeros I just push whatever is convenient (which does happen to include zeros). This is ok since JoKing gets rid of them with a loop that doesn't pick up zeros (which is reversing the stack), I use <> to switch to the other stack.

Other than that shared trick out answers are quite divergent.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ 88 bYTES is a little easier to generate by modifying the end slightly \$\endgroup\$
    – Jo King
    Jul 18, 2020 at 1:45
  • 1
    \$\begingroup\$ Back at you ;). I'm pretty sure 77 or 76 bYTES is possible though, but I've only got that down to 80 bytes \$\endgroup\$
    – Jo King
    Jul 18, 2020 at 7:06
3
\$\begingroup\$

Vyxal , 7 6 bytes

-1 bytes thanks to Bubbler

kṄt`¨ƈ

Explanation

kṄ                - Push "4096"
  t               - Get the final item (6)
   `¨ƈ            - Push "bytes"
<flag>            - Join by spaces ("6 bytes")
<implicit>        - Print it.

Try it Online!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Can't test at the moment, but would it work if you use a numeric constant ending with 6 (e.g. kṄ = 4096) and omit the trailing backtick? (...or just use a different number from the length and increment to get the byte count?) \$\endgroup\$
    – Bubbler
    Oct 19, 2021 at 10:07
  • \$\begingroup\$ It worked, thanks! \$\endgroup\$ Oct 19, 2021 at 11:11
3
\$\begingroup\$

Risky, 32 bytes

*+}*!*1!**/*1*1++*{*1*1!}*}*1+1+*+1**+1!***+{*{+***+1*1!***+!*/

Try it online!

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

Jelly, 7 bytes

“¢>¶ŒD»

Try it online!

Compressed strings.

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

Pyth, 10 bytes

+T" bytes"

Try it here

If you don't mind separating with a newline instead of a space, you can get it down to 8 bytes with

y4"bytes
\$\endgroup\$
2
\$\begingroup\$

J, 19 bytes

echo' bytes',~":_bj

Try it online!

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

C# (.NET Core), 65 bytes

class P{static void Main(){System.Console.Write(0x41+" bytes");}}

Try it online!

\$\endgroup\$
3
  • 1
    \$\begingroup\$ I'm afraid your code contains a 5.. Easily fixed by using 72-7, though. \$\endgroup\$ Mar 29, 2018 at 16:53
  • 2
    \$\begingroup\$ Fixed! With a little bit of hex to make it look clever! =D \$\endgroup\$ Mar 29, 2018 at 17:12
  • \$\begingroup\$ A bit silly and crooked: class Q{static void Main(){new System.Exception("sixty four");}} => 64 and the word bytes is in the exception when you drill down through it! \$\endgroup\$
    – PmanAce
    Mar 29, 2018 at 17:30
2
\$\begingroup\$

SNOBOL4 (CSNOBOL4), 27 bytes

	OUTPUT =3 * 9 ' bytes'
END

Try it online!

prints with a trailing newline.

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

Excel (Immediate Window), 12 bytes

?3*4&"bytes"

This solution assumes that leading space is allowed.
Below the one without leading space in output (14 bytes):

?2*7&&" bytes"

It's the result of suspicious behaviour of the concatenate operator &. When only one, it surrounds the number with spaces; however two consecutive ones strip the spaces. Weird.

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

Ruby, 18 bytes

puts"#{6*3} bytes"

Try it online!

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

brainfuck, 95 bytes

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

Try it online!

97 bytes:

>-[++>+[+<]>]>+.--.>++++[->++++++++<]>.[->+++<]>++.[--->+<]>+++.-----.+++[->+++<]>.[--->+<]>----.
\$\endgroup\$
2
\$\begingroup\$

CJam, 10 10 bytes

Ao" bytes"

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ +1 for the no-op space used just to pad the byte count. Too bad CJam doesn't have a predefined variable with the initial value 9. \$\endgroup\$ Mar 30, 2018 at 0:10
  • \$\begingroup\$ ...although I just realized that the challenge forbids "[u]nnecessary spaces and newlines". But you could still do e.g. " bytes"A\ or A" bytes"+ to comply with the rules as specified. \$\endgroup\$ Mar 30, 2018 at 0:34
  • \$\begingroup\$ @IlmariKaronen Ao" bytes" works. \$\endgroup\$ Mar 30, 2018 at 3:10
1
2
3 4 5
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.