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

1
\$\begingroup\$

Jelly, 7 bytes

“¢>¶ŒD»

Try it online!

Compressed strings.

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

SOGL V0.12, 8 bytes

┌`m39Σ³‘

Try it Here!

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

Pari/GP, 18 bytes

print(2*9" bytes")

Try it online!

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

MATL, 12 bytes

6EV' bytes'h

Try it online!

Pushes 6, doubles with E, converts that to a string with V, and horzcats it with the string ' bytes' to get the proper spacing. Implicit output takes care of the rest.

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

Jotlin, 17 bytes

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

Uses the println builtin

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

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\$
  • \$\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 '18 at 22:21
1
\$\begingroup\$

Python 2, 18 17 bytes

print 8+9,'bytes'

-1 byte thanks to @Wondercricket.

Try it online.

\$\endgroup\$
  • \$\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\$ – Ørjan Johansen Mar 30 '18 at 0:48
  • \$\begingroup\$ @ØrjanJohansen I changed it to 8+9 instead to save a byte. :) \$\endgroup\$ – Kevin Cruijssen Mar 30 '18 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\$

C, 50 49 bytes

#include<stdio.h>
main(){printf("%d bytes",'1');}
\$\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\$

ArnoldC, 216 Bytes

Try it online!

IT'S SHOWTIME
    HEY CHRISTMAS TREE i
    YOU SET US UP 4
    GET TO THE CHOPPER i
        HERE IS MY INVITATION i
        YOU'RE FIRED 54
    ENOUGH TALK
    TALK TO THE HAND i
    TALK TO THE HAND "BYTES"
YOU HAVE BEEN TERMINATED

Output

216
BYTES

Well, i took too long with my php answer, i had to try this.

As far as i read, i can't write without a line break or concatenate an integer with a string :(

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

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

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

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