Code Golf: Code Golf

From Rosetta Code
Revision as of 19:15, 9 December 2021 by Boreal (talk | contribs) (Added X86 assembly language example.)
Code Golf: Code Golf is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Show the shortest possible program that will emit the string “Code Golf”, without the quotation marks and without anything after the final “f”.

Wren

Well, this has no quotation marks and there's nothing after the final "f" but it's a bit lengthy at 76 characters (79 if you count the implicit \n at the end of the first three lines). Note that Wren's single pass compiler allows the last line though it does nothing. <lang ecmascript>class Code{} class Golf{} System.writeAll([Code,String.fromByte(32),Golf]) Golf</lang>

Output:
Code Golf

To print the string "Code Golf" with the quotation marks but with no quotation marks in the script itself would require a minimum of 90 characters (92 including the \n's). <lang ecmascript>class f{} for(c in[-66,-33,11,0,1,-68,-29,11,8,2,-66])System.write(String.fromByte(c+100)) f</lang>

Output:
"Code Golf"

X86 Assembly

This is 100 bytes long (with CR+LF line endings). More useful than small, obfuscated source is small executable. This makes a 17-byte .COM file under MS-DOS. Assemble with: tasm and tlink /t. The xchg instruction is a single byte (as opposed to a straightforward 2-byte mov ah,9), and it takes advantage of the high byte of register bp being set to 09h when the program is started by MS-DOS. 09h selects the "display string" function. <lang asm>.model tiny .code org 256 s:xchg ax,bp mov dx,offset m int 33 ret m db "Code Golf$" end s</lang>

XPL0

This is 19 bytes long. I hate to say how big the executable is, but it's 54,400 bytes on the Raspberry Pi. Under MS-DOS a version of the compiler produces an executable as small as 6674 bytes. <lang XPL0> Text(0,"Code Golf")</lang>