Code Golf: Code Golf: Difference between revisions

m
(Python: shorter code)
 
(68 intermediate revisions by 25 users not shown)
Line 4:
 
Extra credit: how big is the executable required to perform the first task? Skip details about any prior compilation steps that might be involved.
 
=={{header|11l}}==
{{trans|Python}}
 
Using string literals, the following weighs in at 23 bytes.
<syntaxhighlight lang="11l">print(end' ‘Code Golf’)</syntaxhighlight>
 
Without string literals, this is 60 bytes long.
<syntaxhighlight lang="11l">L(c)[37,9,2,3,70,33,9,10,0]{print(end' Char(code' c(+)102))}</syntaxhighlight>
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits <br> or android 64 bits with application Termux }}
<syntaxhighlight lang AArch64 Assembly>
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program codegolf64.s */
 
/*********************************/
/* Initialized data */
/*********************************/
.data
szString: .asciz "codeGolf"
.equ SIZESTRING, . - szString
/*********************************/
/* code section */
/*********************************/
.text
.global main
main: // entry of program
mov x2,SIZESTRING // string length
ldr x1,=szString
mov x0,1 // output Linux standard
mov x8,64 // code call system "write"
svc 0
 
 
mov x0,0 // return code
mov x8,93 // request to exit program
svc #0 // perform the system call
</syntaxhighlight>
{{Out}}
<pre>
Compilation 64 bits Rosetta de codegolf64.s
-rwx------ 1 u0_a344 u0_a344 1144 May 24 21:48 codegolf64
-rw------- 1 u0_a344 u0_a344 960 May 24 21:48 codegolf64.o
-rw------- 1 u0_a344 u0_a344 813 May 24 21:45 codegolf64.s
Fin de compilation.
~/.../rosetta/asm4 $ codegolf64
codeGolf~/.../rosetta/asm4 $
</pre>
 
=={{header|Ada}}==
With String literal:
<syntaxhighlight lang="ada">
with Ada.Text_IO;procedure C is begin Ada.Text_IO.Put("Code Golf");end;
</syntaxhighlight>
71 characters
 
Without Character or String literals (all one line):
<syntaxhighlight lang="ada">
with Ada.Text_IO;procedure C is L:array(1 .. 9)of Integer:=(67,111,100,101,32,71,111,108,102);begin for C of L loop Ada.Text_IO.Put(Character'Val(C));end loop;end;
</syntaxhighlight>
163 characters; this should be portable to all Ada-12 compilers and all platforms
 
If we presume Linux, GNAT, and an executable name of "Code Golf", this can be shortened to (all one line):
<syntaxhighlight lang="ada">
with Ada.Command_Line;with Ada.Text_IO;procedure C is begin Ada.Text_IO.Put(Ada.Command_Line.Command_Name(3..11));end;
</syntaxhighlight>
118 Characters
 
=={{header|6502 Assembly}}==
Line 60 ⟶ 127:
 
===Without Quoted Literals===
Source file size is 6765 bytes (says Windows DIR); as noted above, ALGOL 68G is an interpreter so there isn't a compiled object. The interpreter itself is 2780 K.<br>
Declares and uses a unary operator ! which is effectively an abbreviation for REPR (which converts an INT to a CHAR) and then uses this with the builtin + operator which appends CHARs or STRINGS to form another STRING.
<syntaxhighlight lang="algol68">OP!=(INTc)CHAR:REPR(111-c+32);print(!3544+!790+!6811+!6910+!079+!3940+!790+!763+!709)</syntaxhighlight>
{{out}}
<pre>Code Golf</pre>
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi <br> or android 32 bits with application Termux}}
<syntaxhighlight lang ARM Assembly>
/* ARM assembly Raspberry PI */
/* program codegolf.s */
 
/*********************************/
=={{header|Arturo}}==
/* Initialized data */
/*********************************/
.data
szString: .asciz "codeGolf"
.equ SIZESTRING, . - szString
/*********************************/
/* code section */
/*********************************/
.text
.global main
main: @ entry of program
mov r2,#SIZESTRING @ string length
ldr r1,=szString
mov r0,#1 @ output Linux standard
mov r7,#4 @ code call system "write"
svc 0
 
mov r0, #0 @ return code
<syntaxhighlight lang="rebol">print"Code Golf"
mov r7, #1 @ request to exit program
print join to[:char][67 111 100 101 32 71 111 108 102]</syntaxhighlight>
svc #0 @ perform the system call
 
</syntaxhighlight>
{{Out}}
<pre>
Compilation 32 bits de codegolf.s
-rwx------ 1 u0_a252 u0_a252 904 May 24 21:32 codegolf
-rw------- 1 u0_a252 u0_a252 740 May 24 21:32 codegolf.o
-rw------- 1 u0_a252 u0_a252 816 May 24 18:35 codegolf.s
Fin de compilation.
~/.../rosetta/asm4 $ codegolf
codeGolf~/.../rosetta/asm4 $
</pre>
 
=={{header|Arturo}}==
<syntaxhighlight lang="rebol">prints"Code Golf"
prints join to[:char]digits.base:112 1683633059109764774
prints join to[:char][67 111 100 101 32 71 111 108 102]</syntaxhighlight>
{{out}}
<pre>Code GolfCode GolfCode Golf</pre>
 
<pre>Code Golf
Code Golf</pre>
 
=={{header|AWK}}==
<syntaxhighlight lang="AWKawk">
# syntax: GAWK -f CODE_GOLF.AWK
#
Line 88 ⟶ 191:
# This is a completely stand-alone executable.
#
# 2524 bytes
BEGIN{print(printf"Code Golf")}</syntaxhighlight>
Using a string literal as conversion argument only:
# 52 bytes
<syntaxhighlight lang="awk">
BEGIN{print("\x43\x6F\x64\x65\x20\x47\x6F\x6C\x66")}
# 64 bytes
BEGIN{print("\103\157\144\145\040\107\157\154\146")}
BEGIN{for(n=15162543273030444;n;n=int(n/80))printf"%c",111-n%80}</syntaxhighlight>
This should work with POSIX-compliant implementations (support for hex literals is not mandatory), in double-precision floating-point arithmetic.
{{out}}
 
<pre>
=={{header|Bash}}==
Code Golf
{{works with|UNIX_Shell}}
Code Golf
The directly executable source code is 14 bytes by using its script name instead of character literals:
Code Golf
<syntaxhighlight lang="sh">echo -n ${0:2}</syntaxhighlight>
</pre>
To run:
<syntaxhighlight lang="sh">./Code\ Golf</syntaxhighlight>
 
=={{header|BASIC256BASIC}}==
==={{header|BASIC256}}===
With a quoted string, the following weighs in at 12 bytes.
<syntaxhighlight lang="freebasic">?"Code Golf"</syntaxhighlight>
Line 112 ⟶ 218:
 
Note: BASIC256 is an interpreter, it does not generate executables.
 
==={{header|SmallBASIC}}===
12 characters with a quoted string:
<syntaxhighlight lang="qbasic">?"Code Golf"</syntaxhighlight>
 
49 characters without quoted literals:
<syntaxhighlight lang="qbasic">FOR i in [44,0,11,10,79,40,0,3,9] DO ?CHR(111-i);</syntaxhighlight>
 
=={{header|Binary Lambda Calculus}}==
shortest: 10 bytes
<pre>*Code Golf</pre>
avoiding ASCII: 23 bytes
<pre>46 60 17 ac 23 40 b0 02 cf f7 97 f7 ee 80 bc 90 9b 9a df b8 90 93 99</pre>
 
=={{header|BQN}}==
By using a string literal:
The second line printed is the automatically printed return value from the REPL.
<syntaxhighlight lang="bqn"> •Out"Code Golf"</syntaxhighlight>
Without quoted literals:
<syntaxhighlight lang="bqn">•Out@+111-44‿0‿11‿10‿79‿40‿0‿3‿9</syntaxhighlight>
 
=={{header|C}}==
 
The following answers assume compilation using gcc 11.3.0 on ubuntu 22.04, without using any special options and ignoring the warnings.
 
The shortest possible program (28 bytes) to print the required string is:
<syntaxhighlight lang="c">main(){printf("Code Golf");}</syntaxhighlight>
 
The size of the executable needed to run this is 15,960 bytes.
 
If the program itself cannot contain string or character literals, then the shortest program I've been able to come up with (50 bytes) is:
 
<syntaxhighlight lang="c">a[]={0x65646f43,0x6c6f4720,102};main(){printf(a);}</syntaxhighlight>
 
The size of the executable needed is now 15,992 bytes.
 
Output in both cases:
<pre>
Code Golf
</pre>
"Code Golf"
 
•Out' '+35‿79‿68‿69‿0‿39‿79‿76‿70
=={{header|dc}}==
By using a string literal (12 characters):
<syntaxhighlight lang="dc">[Code Golf]P</syntaxhighlight>
Without quoted literals (22 characters):
<syntaxhighlight lang="dc">16i436F646520476F6C66P</syntaxhighlight>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|}}
Delphi says the code size is 5,180 bytes. Looking at the assembly language that is generated, the size is 132 bytes. The difference must be the Windows overhead for a console application.
<syntaxhighlight lang="Delphi">
program Project1;
{$APPTYPE CONSOLE}
begin
WriteLn('code golf');
WriteLn(#67,#111,#100,#101,#32,#71,#111,#108,#102);
end.
</syntaxhighlight>
{{out}}
<pre>
Code Golf
"Code Golf"</syntaxhighlight>
</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight>
# with string literal (16 characters)
write"Code Golf"
# without quoted literals (54 characters)
# for i in [44 0 11 10 79 40 0 3 9]write strchar(111-i).
for i in [44 0 11 10 79 40 0 3 9]write strchar(111-i).
</syntaxhighlight>
 
=={{header|EMal}}==
<syntaxhighlight lang="emal">
write("Code Golf")
^|EMal supports blobs (byte arrays) that can be initialized with single bytes|^
write(blob().of(67,111,100,101,32,71,111,108,102))
</syntaxhighlight>
{{out}}
<pre>
Code GolfCode Golf
</pre>
 
=={{header|Factor}}==
Line 129 ⟶ 309:
 
=={{header|FreeBASIC}}==
With a quoted string, the following weighs in at 1213 bytes.
<syntaxhighlight lang="freebasic">?"Code Golf";</syntaxhighlight>
Without quoted literals, this is 77 bytes long.
 
<syntaxhighlight lang="freebasic">dim as byte i,a(8)={44,0,11,10,79,40,0,3,9}:for i=0 to 8:?chr(111-a(i));:next</syntaxhighlight>
For the second task, this is 80 bytes long.
<syntaxhighlight lang="freebasic">dim as byte i,a(8)={37,81,70,71,2,41,81,78,72}
for i=0 to 8
?chr(30+a(i));
next</syntaxhighlight>
 
Both compile to a file 27,016 bytes long.
 
Line 148 ⟶ 323:
{{out}}<pre>Code Golf</pre>
 
=={{header|FutureBasic}}==
The shortest way (15 chars) is to use the '''stop''' function. Using the '''print''' function prints to a window, but it vanishes instantly without adding the lengthy '''handleevents''', which allows the code to be interactive.
<syntaxhighlight lang="futurebasic">
stop"Code Golf"
</syntaxhighlight>
Without literals, I poked two values into a string, then printed it with the '''stop''' function: 50 chars.
<syntaxhighlight lang="futurebasic">
str15 s:~@s,0x6F472065646F4309:%@s+8,0x666C:stop s
</syntaxhighlight>
Both produce this result:
{{out}}
[[File:Code Golf.png]]
=={{header|Go}}==
Go isn't well equipped for Code Golf as a certain amount of ceremony (''package main'' and ''func main()'') are needed for any executable.
Line 198 ⟶ 385:
 
(Note: if we were careful about the current directory we were in when we executed this program, we could eliminate the part that swaps <code>-</code> and <code>/</code> characters ((a.C.~<45 47){~a.i.). Removing those 19 characters and creating four directories to hold the program and invoking the program as "exit'Code Golf'fwrite'"/proc/self/fd/"1'" might even be within the spirit of this task. However... we'll leave that as an exercise for the reader...)
 
Alternatively, if we are interested in the size of the J executable, jconsole currently clocks in at 140k bytes. However, this is misleading, as it ignores the size of necessary shared libraries (not to mention the OS Kernel and necessary supporting files)...
 
=={{header|Joy}}==
By using a string literal (20 characters):
<syntaxhighlight lang="Joy">"Code Golf"putchars.</syntaxhighlight>
Without string literals (48 characters):
<syntaxhighlight lang="Joy">[35 79 68 69 0 39 79 76 70][32 + chr putch]step.</syntaxhighlight>
 
=={{header|jq}}==
Line 208 ⟶ 403:
9
</pre>
For the second task, the following program clocks in at 4138 bytes:
<syntaxhighlight lang="text">[-3344,0,11,010,179,-6840,-290,11,83,29|111-.+100]|implode</syntaxhighlight>
 
'''Extra credit''':
The jq executable on my Mac is 461,864 bytes; gojq's is over 8 times larger.
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">print("Code Golf")
 
print(String(Char.([67,111,100,101,32,71,111,108,102])))
</syntaxhighlight>
 
=={{header|Kotlin}}==
Shortest program:
<syntaxhighlight lang="kotlin">fun main()=print("Code Golf")</syntaxhighlight>
Without string literals, JVM only:
<syntaxhighlight lang="kotlin">fun main()=print(String(byteArrayOf(67,111,100,101,32,71,111,108,102)))</syntaxhighlight>
Without string literals, platform-independent:
<syntaxhighlight lang="kotlin">fun main()=print(byteArrayOf(67,111,100,101,32,71,111,108,102).decodeToString())</syntaxhighlight>
A shorter but hacky version:
<syntaxhighlight lang="kotlin">fun main(){listOf(35,79,68,69,0,39,79,76,70).map{print(' '+it)}}</syntaxhighlight>
 
=={{header|Ksh}}==
{{works with|ksh93}}
By just passing strings (17 bytes):
<syntaxhighlight lang="sh">echo -n Code Golf</syntaxhighlight>
Let the shell generate every character (54 bytes):
<syntaxhighlight lang="sh">typeset -i43 a=3066215 b=3384588;echo -n ${a:3} ${b:3}</syntaxhighlight>
Or, in case format strings are allowed for conversion (36 bytes):
<syntaxhighlight lang="sh">printf %..39d%5..43d 2291147 3384588</syntaxhighlight>
 
=={{header|Lang}}==
With text literal (19 Bytes):
<syntaxhighlight lang="lang">fn.print(Code Golf)</syntaxhighlight>
Without text literal (88 Bytes):
<syntaxhighlight lang="lang">parser.op(print(join(\e, arrayMapToNew([67,111,100,101,32,71,111,108,102], fn.toChar))))</syntaxhighlight>
 
=={{header|Lua}}==
With string literal (21 characters):
<syntaxhighlight lang="lua">io.write("Code Golf")</syntaxhighlight>
Without quoted literals (55 characters):
<syntaxhighlight lang="lua">io.write(string.char(67,111,100,101,32,71,111,108,102))</syntaxhighlight>
 
=={{header|Microsoft Small Basic}}==
Using a string literal, this program is 29 bytes long.
<syntaxhighlight lang="smallbasic">TextWindow.Write("Code Golf")</syntaxhighlight>
Without a string literal, the program is 221 bytes long.
<syntaxhighlight lang="smallbasic">TextWindow.Write(Text.GetCharacter(67)+Text.GetCharacter(111)+Text.GetCharacter(100)+Text.GetCharacter(101)+Text.GetCharacter(32)+Text.GetCharacter(71)+Text.GetCharacter(111)+Text.GetCharacter(108)+Text.GetCharacter(102))</syntaxhighlight>
 
=={{header|min}}==
{{works with|min|0.37.0}}
By using a string literal (16 characters):
<syntaxhighlight lang="min">"Code Golf"print</syntaxhighlight>
Without string literals (52 characters):
<syntaxhighlight lang="min">(35 79 68 69 0 39 79 76 70) (32+ chr putchr) foreach</syntaxhighlight>
 
=={{header|Nim}}==
Using a string literal (24 characters):
<syntaxhighlight lang="Nim">stdout.write "Code Golf"
</syntaxhighlight>
 
Compiling on Linux with Nim 1.6.12 using command <code>nim c -d:danger --opt:size -d:lto --gc:arc code_golf.nim</code>, the executable size is 23584 bytes.
 
 
Without string literals (61 characters):
<syntaxhighlight lang="Nim">for n in[67,111,100,101,32,71,111,108,102]:stdout.write n.chr
</syntaxhighlight>
 
Compiling on Linux with Nim 1.6.12 using command <code>nim c -d:danger --opt:size -d:lto --gc:arc code_golf.nim</code>, the executable size is 22528 bytes.
 
=={{header|OCaml}}==
With string literal (29 characters):
<syntaxhighlight lang="ocaml">let()=print_string"Code Golf"</syntaxhighlight>
Without quoted literals (7875 characters):
<syntaxhighlight lang="ocaml">let()=List.iter(fun c->print_char(char_of_intChar.chr(111-c)))[44;0;11;10;79;40;0;3;9]</syntaxhighlight>
 
=={{header|Openscad}}==
Line 234 ⟶ 493:
 
=={{header|Perl}}==
Using a string literal:
<syntaxhighlight lang="perl">
# 1 2
#12345678901234567890
print 'Code Golf' # 1716 bytes</syntaxhighlight>
Without quoted literals:
; print "\n";
<syntaxhighlight lang="perl">
 
# 1 2 3 4 5
#12345678901234567890123456789012345678901234567890
print map{chr(102^$_^102)}for 37,9,2,3,70,33,9,10,0 # 4342 bytes</syntaxhighlight>
; print "\n";</syntaxhighlight>
 
=={{header|Phix}}==
<!--<syntaxhighlight lang="Phix">(phixonline)-->
<syntaxhighlight lang="Phix">
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Code Golf"</span><span style="color: #0000FF;">)</span>
puts(1,"Code Golf")
<!--</syntaxhighlight>-->
</syntaxhighlight>
Which is 19 bytes. Note that <code>?"Code Golf"</code>, while only 12 bytes, ''does'' print the quotation marks and therefore does not meet the task specifications.<br>
Without using string literals, at 42 bytes we can have
<!--<syntaxhighlight lang="Phix">(phixonline)-->
puts(1,{67,111,100,101,32,71,111,108,102})
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">67</span><span style="color: #0000FF;">,</span><span style="color: #000000;">111</span><span style="color: #0000FF;">,</span><span style="color: #000000;">100</span><span style="color: #0000FF;">,</span><span style="color: #000000;">101</span><span style="color: #0000FF;">,</span><span style="color: #000000;">32</span><span style="color: #0000FF;">,</span><span style="color: #000000;">71</span><span style="color: #0000FF;">,</span><span style="color: #000000;">111</span><span style="color: #0000FF;">,</span><span style="color: #000000;">108</span><span style="color: #0000FF;">,</span><span style="color: #000000;">102</span><span style="color: #0000FF;">})</span>
<!--</syntaxhighlight>-->
Or quite long but deliciously cryptic:
<syntaxhighlight lang="Phix">
puts(1,atom_to_float64(1.276409856e-152)[4..$]&
atom_to_float64(1.458406353e-258)[4..$])
</syntaxhighlight>
Slightly shorter, at 30 bytes, though it could be considered string/char:
<!--<syntaxhighlight lang="Phix">(phixonline)-->
puts(1,x"436F646520476F6C66")
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span>x"<span style="color: #0000FF;">436F646520476F6C66</span>"<span style="color: #0000FF;">)</span>
<!--</syntaxhighlight>-->
While not exactly shorter, if you name the source code as Code Golf[.exw] or the executable as Code Golf[.exe], perhaps needing a substitute(s,'_',' ') [or (..,95,32)], this approach will also work:
<syntaxhighlight lang="Phix">
puts(1,get_file_base(command_line()[2]))
</syntaxhighlight>
The compiled size of the first is 276,992 bytes.
You can actually make a smaller executable as follows:
<!--<syntaxhighlight lang="Phix">(phixonline)-->
include puts1h.e
<span style="color: #008080;">include</span> <span style="color: #000000;">puts1h</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
puts1("Code Golf")
<span style="color: #000000;">puts1</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"Code Golf"</span><span style="color: #0000FF;">)</span>
<!--</syntaxhighlight>-->
Then compile it with p -c -nodiag ''test.exw'' (or whatever) to yield an executable of 36,532 bytes -
no diagnostics, which is itself non-trivial and otherwise pulls in file handling (for the ex.err it writes),
Line 271 ⟶ 540:
of subscript stuff we don't rightly need... still I suppose 36K ain't really all that bad.
Oh, I should also say the compiler/interpreter/linker/debugger is itself (currently) 2,789,376 bytes, plus you'll still need most of builtins/ which is around the 9MB mark.
 
 
=={{header|Phixmonti}}==
Line 302 ⟶ 570:
{{out}}
<pre>Code Golf</pre>
 
=={{header|Plain English}}==
Using a string literal, this program is 89 bytes long.
<syntaxhighlight lang="text">To run:Start up.Write"Code Golf"to the console without advancing.Wait for the escape key.</syntaxhighlight>
Without a string literal, the program is 98 bytes long.
<syntaxhighlight lang="text">To run:Start up.Write$436F646520476F6C66 to the console without advancing.Wait for the escape key.</syntaxhighlight>
The executable compiled by the Plain English compiler weighs in at 143,360 bytes.
 
=={{header|PureBasic}}==
Line 367 ⟶ 642:
{{out}}
<pre>Code Golf</pre>
 
 
=={{header|True BASIC}}==
With a quoted string, the following weighs in at 22 bytes.
<syntaxhighlight lang="qbasic">PRINT "Code Golf"
END</syntaxhighlight>
 
For the second task, this is 100 bytes long.
<syntaxhighlight lang="qbasic">DIM a(9)
DATA 37,81,70,71,2,41,81,78,72
FOR i=1 to 9
READ a(i)
PRINT CHR$(30+a(i));
NEXT i
END</syntaxhighlight>
 
 
=={{header|Raku}}==
Line 392 ⟶ 651:
Assuming we can't use the string literal in the source, the shortest I've come up with is:
 
<syntaxhighlight lang="raku" line>print chrs (-3237,12,19,2,-673,-2870,1233,9,3)10,0 »X+»99^102 # 4539 Charschars, 4739 bytes</syntaxhighlight>
[https://tio.run/##K0gtyjH7/7@gKDOvRCE5o6hYwdhcx1LHSMdYx9xAx9gYyDY00DFQiNCOMzQw@v8fAA Try it online!]
<syntaxhighlight lang="raku" line>print chrs (-3,㊶,㉚,㉛,-㊳,1,㊶,㊳,㉜) »+»㉎ # 37 Chars, 56 bytes</syntaxhighlight>
<syntaxhighlight lang="raku" line>print chrs -3,㊶,㉚,㉛,-㊳,1,㊶,㊳,㉜X+㉎ # 33 Chars, 49 bytes</syntaxhighlight>[https://tio.run/##K0gtyjH7/7@gKDOvRCE5o6hYQddY53HXNp3HnbOAeLaO7uOuzTqGECEg63HnnAjtx519//8DAA Try it online!]
<syntaxhighlight lang="raku" line>print <Dpef!Hpmg>.ords».pred.chrs # 33 Chars, 34 bytes. Somewhat cheaty as it _does_ contain a string literal, but not the same literal as the output</syntaxhighlight>
Same output for each. Of course, to actually run any of that code you need the Raku compiler at 18.0Kb, the nqp vm interpreter at 17.9 Kb and the moar virtual machine at 17.9Kb. (Or the Java virtual machine, which is remarkably difficult to come up with a size for...)
 
=={{header|REBOL}}==
Using a string literal, this program is 15 bytes long.
<syntaxhighlight lang="rebol">prin"Code Golf"</syntaxhighlight>
Without a string literal, the program is 67 bytes long.
<syntaxhighlight lang="rebol">prin rejoin map-each c[67 111 100 101 32 71 111 108 102][to-char c]</syntaxhighlight>
Or, in case binary literals are allowed, the program is 51 bytes long.
<syntaxhighlight lang="rebol">s: enbase #{1A875E1A895F}insert at s 5 space prin s</syntaxhighlight>
 
=={{header|RPL}}==
≪ "Code Golf" ≫
The above code costs 48 nibbles (e.g. 4 bits) of memory (e.g. 24 bytes); the string itself requires 28 quartets.
≪ #102d #108d #111d #71d #32d #101d #100d #111d 67 CHR 1 8 START SWAP B→R CHR + NEXT ≫
This string-free code costs 233 nibbles (117 bytes). Unsigned integers - numbers starting with a <code>#</code> - have been used whenever possible since they use 9 nibbles less than floating-point numbers to store a value up to #FF
 
=={{header|Ruby}}==
Line 403 ⟶ 677:
# Taken from Perl:
$><<['436F646520476F6C66'].pack('H*') #37 chars</syntaxhighlight>
 
=={{header|Run BASIC}}==
With a quoted string, the following weighs in at 17 bytes.
Line 411 ⟶ 686:
 
Note: Run BASIC is an interpreter, it does not generate executables.
 
=={{header|sed}}==
With sed, we can hardly stick to the rules. It requires at least one byte of input (to run the script at all), and cannot suppress a trailing newline on output.
<syntaxhighlight lang="sh">$ echo | sed 's/.*/Code Golf/'
Code Golf</syntaxhighlight>
Sed cannot translate/insert characters without having the target being specified in the code. So the best we can do, is to hide them behind escape-sequences (even with that, we can't avoid all letters from the target string). And, to limit ourselves a bit, we use each escape-sequence only once). That script is not POSIX-compliant, but works at least with GNU sed.
<syntaxhighlight lang="sh">$ echo | sed 's/.*/\x6f/;s/./\x43&\x64\x65\c`\x47&\x6c\x66/'
Code Golf</syntaxhighlight>
 
=={{header|True BASIC}}==
By using a string literal, the following weighs in at 22 bytes.
<syntaxhighlight lang="qbasic">PRINT "Code Golf";
END</syntaxhighlight>
Without quoted literals, this is 92 bytes long.
<syntaxhighlight lang="qbasic">DIM a(9)
DATA 44,0,11,10,79,40,0,3,9
FOR i=1 to 9
READ a(i)
PRINT CHR$(111-a(i));
NEXT i
END</syntaxhighlight>
 
=={{header|UNIX Shell}}==
By using a string literal (18 characters):
<syntaxhighlight lang="sh">echo 'Code Golf\c'</syntaxhighlight>
By using just a format specifier (56 characters):
<syntaxhighlight lang="sh">printf $(printf \\\\%o 67 111 100 101 32 71 111 108 102)</syntaxhighlight>
 
=={{header|Uxntal}}==
Using a "string literal" / raw ASCII rune (59 characters):
<syntaxhighlight lang="Uxntal">|0100 #0110 2194 06 #18 1720 fff7 #800f 1700 "Code 20 "Golf</syntaxhighlight>
Without raw ASCII runes (67 characters):
<syntaxhighlight lang="Uxntal">|0100 #0110 2194 06 #18 1720 fff7 #800f 1700 436f 6465 2047 6f6c 66</syntaxhighlight>
 
Both programs assemble to the same 26 byte ROM:
<pre>a001 1021 9406 8018 1720 fff7 a080 0f17
0043 6f64 6520 476f 6c66</pre>
 
The 9 byte string accounts for almost 35% of the final ROM.
 
The golfed code works very similarly to the following code:
<syntaxhighlight lang="Uxntal">|00 @System &vector $2 &expansion $2 &wst $1 &rst $1 &metadata $2 &r $2 &g $2 &b $2 &debug $1 &state $1
|10 @Console &vector $2 &read $1 &pad $4 &type $1 &write $1 &error $1
 
|0100
( get pointer to byte before str )
;str #0001 SUB2
@loop
( load a byte, pre-increment, and write it )
INC2 LDAk DUP .Console/write DEO
( loop again if the byte was non-null )
?loop
( exit )
#80 .System/state DEO
BRK
 
@str
"Code 20 "Golf 00</syntaxhighlight>
 
The main trick used in golfing of this program was to encode the raw instruction bytes in hex in the source code.
 
=={{header|Verilog}}==
Line 444 ⟶ 779:
=={{header|Wren}}==
The shortest possible program (25 bytes) to print the required string is:
<syntaxhighlight lang="ecmascriptwren">System.write("Code Golf")</syntaxhighlight>
The size of the executable needed to run this or indeed any other standalone program (Wren-cli on Linux) is 414,760 bytes. However, if Wren were being embedded in a minimal C program, then the size of the executable would be 17,320 bytes.
 
If the program itself cannot contain string or character literals, then the shortest program we've been able to come up with (7168 bytes) - thanks to Thundergnat! - is:
<syntaxhighlight lang="ecmascriptwren">for(c in[-3237,12,19,2,-673,-2870,1233,9,310,0])System.write(String.fromByte(c+99^102))</syntaxhighlight>
{{out}}
In both cases:
Line 488 ⟶ 823:
With a quoted string, the following weighs in at 12 bytes.
<syntaxhighlight lang="yabasic">?"Code Golf"</syntaxhighlight>
Without quoted literals, this is 63 bytes long.
 
<syntaxhighlight lang="yabasic">data 44,0,11,10,79,40,0,3,9:for i=0to 8read n:?chr$(111-n);next</syntaxhighlight>
For the second task, this is 118 bytes long.
<syntaxhighlight lang="yabasic">dim a(8)
a(0)=37:a(1)=81:a(2)=70:a(3)=71
a(4)=2:a(5)=41:a(6)=81:a(7)=78:a(8)=72
for i=0 to 8
?chr$(30+a(i));
next</syntaxhighlight>
 
Note: Yabasic is an interpreter, it does not generate executables.
 
Line 568 ⟶ 896:
[[Category:Simple]]
[[Category:Code Golf]]
 
{{omit from|EasyLang|Print statement must print a new line at the end}}
56

edits