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

143 Answers 143

3
\$\begingroup\$

C, 33 32 bytes

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

There is a trailing newline, which is not "unnecessary" since the C standard demands it. Try it online here.

Thanks to NieDzejkob for golfing 1 byte.

Alternative with the same bytecount, thanks to ErikF:

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

Try it online here.

\$\endgroup\$
  • \$\begingroup\$ , 040 for 32 bytes \$\endgroup\$ – NieDzejkob Mar 29 '18 at 15:58
  • \$\begingroup\$ , 040 is against the (updated) rules but I added a trailing newline instead of the space. Thank you! \$\endgroup\$ – O.O.Balance Mar 29 '18 at 16:25
  • 2
    \$\begingroup\$ You could also use ,' ' to avoid any numerals at all! \$\endgroup\$ – ErikF Mar 30 '18 at 5:51
  • \$\begingroup\$ @ErikF now that is clever. thanks :) \$\endgroup\$ – O.O.Balance Mar 30 '18 at 11:15
  • \$\begingroup\$ 31 bytes \$\endgroup\$ – Steadybox Mar 30 '18 at 11:53
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\$
  • \$\begingroup\$ My Excel shows additional leading space. Is it allowed? \$\endgroup\$ – pajonk Mar 30 '18 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\$ – Taylor Scott Mar 30 '18 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\$
  • \$\begingroup\$ Suggest 063 for (int)'8', 067 for (int)'<' and 070 for (int)'=' \$\endgroup\$ – ceilingcat Apr 1 '18 at 0:09
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\$
3
\$\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\$
  • \$\begingroup\$ It even uses one of the semi-colons 4 times! \$\endgroup\$ – Jo King Sep 28 '18 at 11:20
3
\$\begingroup\$

Forth (gforth), 14 13 bytes

$d . ." bytes

Try it online!

\$\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\$
  • 1
    \$\begingroup\$ I'm afraid your code contains a 5.. Easily fixed by using 72-7, though. \$\endgroup\$ – Kevin Cruijssen Mar 29 '18 at 16:53
  • 2
    \$\begingroup\$ Fixed! With a little bit of hex to make it look clever! =D \$\endgroup\$ – Anderson Pimentel Mar 29 '18 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 '18 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\$
  • \$\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\$ – Ilmari Karonen Mar 30 '18 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\$ – Ilmari Karonen Mar 30 '18 at 0:34
  • \$\begingroup\$ @IlmariKaronen Ao" bytes" works. \$\endgroup\$ – Esolanging Fruit Mar 30 '18 at 3:10
2
\$\begingroup\$

Gol><>, 11 bytes

bn"setyb "H

Try it online!

How it works

bn"setyb "H
b            push number 11
 n           pop and print as integer
  "setyb "   push " bytes" in reverse order
          H  print the stack content as chars, then halt
\$\endgroup\$
2
\$\begingroup\$

Japt, 8 bytes

#+` ßs

char-code 8 concatenated with " bytes" compressed.

Try it online!

\$\endgroup\$
  • 1
    \$\begingroup\$ Identical to what I had, again. would also work. \$\endgroup\$ – Shaggy Apr 2 '18 at 15:56
2
\$\begingroup\$

Google Sheets, 12 bytes

An anonymous worksheet function that takes no input and outputs to the calling cell

=3*4&" bytes
\$\endgroup\$
2
\$\begingroup\$

MSSQL, 26 24 bytes

print str(8*3) +' bytes'
\$\endgroup\$
2
\$\begingroup\$

F#, 24 23 bytes

I hope this counts. Never code golfed before

printfn "%i bytes" 0x17

Just switched 24 to octal 23 to hex

Try it online!

\$\endgroup\$
  • \$\begingroup\$ Welcome to the site! It looks like you have some extraneous whitespace. Could that be removed? Also, I don't know a whole lot about F#, but are you sure this is a full program? The original rules stated write a full program to output it's own score \$\endgroup\$ – DJMcMayhem Mar 30 '18 at 19:52
  • \$\begingroup\$ @DJMcMayhem whoops, dropped that extra space. Also I do believe this is a full program. It compiles and runs just fine in Visual Studio without anything else, though I may misunderstand what that means. \$\endgroup\$ – an earwig Mar 30 '18 at 19:56
  • \$\begingroup\$ Whoops, my bad. I assumed that F# was like C# where you need class declarations in a full program. Looks valid to me! \$\endgroup\$ – DJMcMayhem Mar 30 '18 at 20:04
2
\$\begingroup\$

Windows Command Line, 20 bytes

set/a4*5&echo  bytes

Run Windows Command Prompt (cmd.exe), type the command and hit Enter.

img

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

SQL, 18 bytes

SELECT 2*9,'bytes'
\$\endgroup\$
2
\$\begingroup\$

Swift 4, 19 18 bytes

Saved 1 byte thanks to Jo King.

print(9*2,"bytes")

Try it online!

\$\endgroup\$
  • \$\begingroup\$ Why not 9*2?- \$\endgroup\$ – Jo King Apr 5 '18 at 15:58
  • \$\begingroup\$ @JoKing What an oversight... Thanks! \$\endgroup\$ – xoudini Apr 5 '18 at 16:00
2
\$\begingroup\$

m4, 15 bytes

As in the m4 POSIX macro processor.

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

Vim, 12 10 bytes

i9<C-o><C-a> bytes
\$\endgroup\$
2
\$\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\$
  • \$\begingroup\$ What calculator has a toString( function? \$\endgroup\$ – kamoroso94 Apr 9 '18 at 10:05
  • 1
    \$\begingroup\$ @kamoroso94 The TI-84 Plus CE. Source \$\endgroup\$ – pizzapants184 Apr 9 '18 at 15:06
2
\$\begingroup\$

Backhand, 11 bytes

"" sbbeOytH

Try it online!

Non-linear pointer progression makes for weird looking programs. Outputs 11 bytes.

The orde: of commands is such:

"  s  e  t      Start string literal to push letters
                Bounce and go left
     b  y       Finish pushing " bytes"
                Bounce and go right
 "  b  O  H   Push 11 to print and then halt and output the stack
\$\endgroup\$
2
\$\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\$
2
\$\begingroup\$

Bash, 20 18 17 bytes

echo $[8+9] bytes

Try it online!

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

\$\endgroup\$
  • \$\begingroup\$ echo $[20-2] bytes for 18 bytes? \$\endgroup\$ – manatwork Mar 29 '18 at 17:20
  • \$\begingroup\$ @manatwork woah, I didn't know bash could do math like that \$\endgroup\$ – NieDzejkob Mar 30 '18 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 '18 at 8:37
  • 2
    \$\begingroup\$ echo $[5#33] bytes also works for a score of 18. \$\endgroup\$ – Digital Trauma Mar 30 '18 at 17:40
  • \$\begingroup\$ Doesn’t 8+9 work for 17? \$\endgroup\$ – boboquack Jul 30 at 6:01
1
\$\begingroup\$

Jelly, 7 bytes

“¢>¶ŒD»

Try it online!

Compressed strings.

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