Code Golf: Code Golf: Difference between revisions

m
 
(125 intermediate revisions by 41 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}}==
Not counting vector tables, disk/cartridge headers, and/or font graphics data, here is as small as I could get (example is for commodore 64)
===With Quoted Literals===
<syntaxhighlight lang="6502asm">m
LDX #0
LDA G,x
BEQ d
jsr -46
jmp m+2
d
rts
G
db "Code Golf",0</syntaxhighlight>
 
===Without Quoted Literals===
<syntaxhighlight lang="6502asm">p equ -46
LDA #67
JSR p
LDA #111
JSR p
LDA #100
JSR p
LDA #101
JSR p
LDA #32
JSR p
LDA #71
JSR p
LDA #111
JSR p
LDA #108
JSR p
LDA #102
JMP p</syntaxhighlight>
 
=={{header|Action!}}==
===With Quoted Literals===
<syntaxhighlight lang="action!">PROC M()Print("Code Golf")</syntaxhighlight>
{{out}}
<pre>Code Golf</pre>
 
===Without Quoted Literals===
<syntaxhighlight lang="action!">PROC M()Put(67)Put(111)Put(100)Put(101)Put(32)Put(71)Put(111)Put(108)Put(102)</syntaxhighlight>
{{out}}
<pre>Code Golf</pre>
 
=={{header|ALGOL 68}}==
Line 9 ⟶ 122:
===With Quoted Literals===
Source size is 18 bytes; as ALGOL 68G is an interpreter, there isn't a compiled object. The interpreter itself is 2780 K.
<langsyntaxhighlight lang="algol68">print("Code Golf")</langsyntaxhighlight>
{{out}}
<pre>Code Golf</pre>
 
===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.
<langsyntaxhighlight lang="algol68">OP!=(INTc)CHAR:REPR(111-c+32);print(!3544+!790+!6811+!6910+!079+!3940+!790+!763+!709)</langsyntaxhighlight>
{{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|FreeBASIC}}==
/* 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
mov r7, #1 @ request to exit program
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>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f CODE_GOLF.AWK
#
# Under MS-Windows 10 using Thompson Automation's TAWK 5.0c AWKW -xm
# the compiled length of each program is 34,936 bytes and all three is 35,140 bytes.
# Each requires the Awkr50w.EXE runtime of 231,936 bytes.
#
# Under MS-Windows 10 using Thompson Automation's TAWK 5.0c AWKW -xe
# the compiled length of each program is 244,856 bytes and all three is 245,060 bytes.
# This is a completely stand-alone executable.
#
# 24 bytes
BEGIN{printf"Code Golf"}</syntaxhighlight>
Using a string literal as conversion argument only:
<syntaxhighlight lang="awk">
# 64 bytes
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.
 
=={{header|Bash}}==
{{works with|UNIX_Shell}}
The directly executable source code is 14 bytes by using its script name instead of character literals:
<syntaxhighlight lang="sh">echo -n ${0:2}</syntaxhighlight>
To run:
<syntaxhighlight lang="sh">./Code\ Golf</syntaxhighlight>
 
=={{header|BASIC}}==
==={{header|BASIC256}}===
With a quoted string, the following weighs in at 12 bytes.
<langsyntaxhighlight lang="freebasic">?"Code Golf"</langsyntaxhighlight>
 
For the second task, this is 8066 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</langsyntaxhighlight>
 
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:
<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>
 
=={{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
</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}}==
{{works with|Factor|0.99 2020-08-14}}
<syntaxhighlight lang="factor">[I Code GolfI]
{ 67 111 100 101 32 71 111 108 102 } write</syntaxhighlight>
The executable is 2,265 KB.
 
=={{header|FreeBASIC}}==
With a quoted string, the following weighs in at 13 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>
Both compile to a file 27,016 bytes long.
 
=={{header|Free Pascal}}==
"Code Golf" as Hex in little Endian ending in 0x00
86 byte. linux executable fpc 3.2.2 : 8x386 183400 Byte | x64 191104 byte
<syntaxhighlight lang="pascal">
var a:QWord=$006F472065646F43;b:DWord=$0000666C;BEGIN write(pChar(@a),pChar(@b));END.
</syntaxhighlight>
{{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.
 
The shortest possible program (44 bytes) to print the required string is:
<syntaxhighlight lang="go">package main;func main(){print("Code Golf")}</syntaxhighlight>
 
If the program itself cannot contain string or character literals, then the shortest program I've been able to come up with (81 bytes) is:
<syntaxhighlight lang="go">package main;func main(){print(string([]byte{67,111,100,101,32,71,111,108,102}))}</syntaxhighlight>
Output in both cases
<pre>
Code Golf
</pre>
The size of the executables are 1,158,158 and 1,158,174 bytes respectively though this will obviously depend on Go version, platform and build options being used.
 
=={{header|Golfscript}}==
With a quoted string, the following weighs in at 11 bytes.
<syntaxhighlight lang="golfscript">"Code Golf"</syntaxhighlight>
 
For the second task, this is 78 bytes long.
<syntaxhighlight lang="golfscript">67[]+''+111[]+''+100[]+''+101[]+''+32[]+''+71[]+''+111[]+''+108[]+''+102[]+''+</syntaxhighlight>
{{out}}
In both cases:
<pre>Code Golf</pre>
 
=={{header|J}}==
 
For this bit of silliness, eliminating a trailing newline on stdout is probably the most difficult issue. So, we limit our implementation to linux and use /proc/self/fd/1
 
Sadly, we need to use a character literal to reference /proc/self/fd/1
 
But we do not need that reference to live in the implementation -- this task explicitly allows us to use the name of the running program.
 
So, our program looks like this:
 
<pre>#!/usr/bin/env jconsole
exit".(a.C.~<45 47){~a.i.;}.ARGV</pre>
 
And we name our program <code>"exit'Code Golf'fwrite'-proc-self-fd-1'"</code>
 
Here's an example bash session, illustrating this incredibly useful program:
 
<pre>$ "exit'Code Golf'fwrite'-proc-self-fd-1'" | wc
0 2 9
$ "exit'Code Golf'fwrite'-proc-self-fd-1'"
Code Golf$</pre>
 
Extra Credit: this program occupies 57 bytes (ignoring OS overhead, such as the name of the routine and the minimum size allocated to any file with any content).
 
(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 41 ⟶ 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</langsyntaxhighlight>
 
'''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 (75 characters):
<syntaxhighlight lang="ocaml">let()=List.iter(fun c->print_char(Char.chr(111-c)))[44;0;11;10;79;40;0;3;9]</syntaxhighlight>
 
=={{header|Openscad}}==
With a quoted string, the following weighs in at 18 bytes.
<syntaxhighlight lang="openscad">text("Code Golf");</syntaxhighlight>
 
For the second task, this is 46 bytes long.
<syntaxhighlight lang="openscad">text(chr([67,111,100,101,32,71,111,108,102]));</syntaxhighlight>
 
=={{header|Pascal}}==
The shortest ISO-compliant Pascal program is 46 characters.
==={{header|Free Pascal}}===
<syntaxhighlight lang="pascal">program p(output);begin write('Code Golf')end.</syntaxhighlight>
"Code Golf" as Hex in little Endian ending in 0x00
Unless you make certain presumptions about the target system, you cannot achieve the second task in Pascal (as defined by the ISO standards).
86 byte. linux executable fpc 3.2.2 : 8x386 183400 Byte | x64 191104 byte
Therefore, see [[#Free Pascal|Free Pascal]] for one method.
<lang pascal>
 
var a:QWord=$006F472065646F43;b:DWord=$0000666C;BEGIN write(pChar(@a),pChar(@b));END.
=={{header|Perl}}==
</lang>
Using a string literal:
{{out}}<pre>Code Golf</pre>
<syntaxhighlight lang="perl">
# 1 2
#12345678901234567890
print'Code Golf' # 16 bytes</syntaxhighlight>
Without quoted literals:
<syntaxhighlight lang="perl">
# 1 2 3 4 5
#12345678901234567890123456789012345678901234567890
print chr($_^102)for 37,9,2,3,70,33,9,10,0 # 42 bytes</syntaxhighlight>
 
=={{header|Phix}}==
<!--<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")
<!--</lang>-->
</syntaxhighlight>
Which is 18 bytes. Without using string literals, at 42 bytes we can have
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>
<!--<lang Phix>(phixonline)-->
Without using string literals, at 42 bytes we can have
<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 lang>--="Phix">
puts(1,{67,111,100,101,32,71,111,108,102})
</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">
<!--<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>
<!--</lang>-->
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">
<!--<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>
<!--</lang>-->
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 79 ⟶ 539:
latter also drags in delete() and therefore callfunc and therefore a whole bunch
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}}==
<syntaxhighlight lang="Phixmonti">/# Rosetta Code problem: http://rosettacode.org/wiki/Code_Golf
by Galileo, 10/2022 #/
 
include ..\Utilitys.pmt
 
"Code Golf" ?
 
( 67 111 100 101 32 71 111 108 102 ) len for get tochar print endfor nl
 
def >char tochar enddef
( 67 111 100 101 32 71 111 108 102 ) getid >char map lprint</syntaxhighlight>
{{out}}
<pre>Code Golf
Code Golf
Code Golf</pre>
 
=={{header|Picat}}==
As a string:
<syntaxhighlight lang="Picat">main => "Code Golf".print.</syntaxhighlight>
 
{{out}}
<pre>Code Golf</pre>
 
No quotes:
<syntaxhighlight lang="Picat">main => [67,111,100,101,32,71,111,108,102].map(chr).print.</syntaxhighlight>
 
{{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}}==
With a quoted string, the following weighs in at 18 bytes.
<syntaxhighlight lang="PureBasic">Print("Code Golf")</syntaxhighlight>
 
For the second task, this is 69 bytes long.
<syntaxhighlight lang="PureBasic">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
Print(Chr(30+a(i)))
Next</syntaxhighlight>
 
The size of the executables are 7680 and 10752 bytes respectively though this will obviously depend on PureBasic version, platform and build options being used.
 
=={{header|Python}}==
;Python 3:
Using string literals, the following weighs in at 22 bytes.
<syntaxhighlight lang="python">print(end="Code Golf")</syntaxhighlight>
 
Without string literals, this is 52 bytes long.
<syntaxhighlight lang="python">print(end=0x436f646520476f6c66.to_bytes(9).decode())
 
# or:
 
for c in 37,9,2,3,70,33,9,10,0:print(end=chr(c^102))</syntaxhighlight>
 
=={{header|QBasic}}==
{{works with|QBasic|1.1}}
With a quoted string, the following weighs in at 17 bytes.
<syntaxhighlight lang="qbasic">PRINT "Code Golf"</syntaxhighlight>
 
For the second task, this is 91 bytes long.
<syntaxhighlight lang="qbasic">DIM a(8)
DATA 37,81,70,71,2,41,81,78,72
FOR i = 0 TO 8
READ a(i)
PRINT CHR$(30 + a(i));</syntaxhighlight>
 
Note: QBasic is an interpreter, it does not generate executables.
 
 
=={{header|Quackery}}==
 
===With Quoted Literals===
 
<syntaxhighlight lang="Quackery">say "Code Golf"</syntaxhighlight>
 
===Without Quoted Literals===
 
<code>' [ 67 111 100 101 32 71 111 108 102 ] echo$</code> is marginally shorter but less interesting. For longer strings, encoding the text as a bignum rapidly becomes the more space efficient option. The text "Code Golf" is not quite long enough for the obvious improvement of using hexadecimal rather than decimal, as the digit reduction is less than the four character overhead of putting <code>hex</code> and a space before the number.
 
<syntaxhighlight lang="Quackery">2549578149779768531 9 times [ 112 /mod emit ] drop</syntaxhighlight>
 
=={{header|R}}==
I suspect there may be shorter methods, but these are my best attempt.
<syntaxhighlight lang="R">## easy way
cat("Code Golf")
 
## no quotes or string literals
cat(rlang::string(c(0x43, 0x6F, 0x64, 0x65, 0x20,
0x47, 0x6F, 0x6C, 0x66)))
</syntaxhighlight>
{{out}}
<pre>Code Golf</pre>
 
=={{header|Raku}}==
Not very interesting, as it's pretty much just standard, non-obscure Raku. The output string is so short, there isn't any easy way to golf it shorter than just printing it directly. 17 bytes.
<syntaxhighlight lang="raku" perl6line>print <Code Golf></langsyntaxhighlight>
{{out}}
<pre>Code Golf</pre>
Line 88 ⟶ 651:
Assuming we can't use the string literal in the source, the shortest I've come up with is:
 
<syntaxhighlight lang="raku" perl6line>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!]
print chrs (-3,㊶,㉚,㉛,-㊳,1,㊶,㊳,㉜) »+»㉎ # 37 Chars, 56 bytes</lang>
<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}}==
Same output, 45 characters, 47 bytes. Of course, to actually run 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...)
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}}==
<syntaxhighlight lang="Ruby">
$><<"Code Golf" #15 chars
puts
# Taken from Perl:
$><<['436F646520476F6C66'].pack('H*') #37 chars</syntaxhighlight>
 
=={{header|Run BASIC}}==
With a quoted string, the following weighs in at 17 bytes.
<syntaxhighlight lang="freebasic">print "Code Golf"</syntaxhighlight>
 
For the second task, this is 82 bytes long.
<syntaxhighlight lang="freebasic">dim a(8):data 37,81,70,71,2,41,81,78,72:for i=0 to 8:read j:print chr$(30+j);:next</syntaxhighlight>
 
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}}==
With a quoted string, the following weighs in at 64 bytes.
<syntaxhighlight lang="Verilog">module main;
initial begin $write("Code Golf");
end
endmodule</syntaxhighlight>
 
For the second task, this is 102 bytes long.
 
<syntaxhighlight lang="Verilog">module main;
initial begin $write("%c%c%c%c %c%c%c%c",67,111,100,101,71,111,108,102);
end
endmodule</syntaxhighlight>
{{out}}
In both cases:
<pre>Code Golf</pre>
 
=={{header|V (Vlang)}}==
{{trans|go}}
 
The shortest possible program to print the required string is:
<syntaxhighlight lang="go">print("Code Golf")</syntaxhighlight>
If the program itself cannot contain string or character literals, then use byte list:
<syntaxhighlight lang="go">print([u8(67),111,100,101,32,71,111,108,102].bytestr())</syntaxhighlight>
Output in both cases
<pre>
Code Golf
</pre>
 
=={{header|Wren}}==
The shortest possible program (25 bytes) to print the required string is:
<langsyntaxhighlight ecmascriptlang="wren">System.write("Code Golf")</langsyntaxhighlight>
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:
<langsyntaxhighlight ecmascriptlang="wren">for(c in[-3237,12,19,2,-673,-2870,1233,9,310,0])System.write(String.fromByte(c+99^102))</langsyntaxhighlight>
{{out}}
In both cases:
Line 113 ⟶ 797:
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.
<langsyntaxhighlight lang="asm">.model tiny
.code
org 256
Line 121 ⟶ 805:
ret
m db "Code Golf$"
end s</langsyntaxhighlight>
 
=={{header|XPL0}}==
Line 127 ⟶ 811:
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.
<langsyntaxhighlight lang="XPL0">Text(0,"Code Golf")</langsyntaxhighlight>
This version without a string or character literals is 33 characters
long.
<langsyntaxhighlight lang="XPL0">Text(0,[$65646f43,$6c6f4720,$e6])</langsyntaxhighlight>
{{out}}
<pre>
Line 136 ⟶ 820:
</pre>
 
=={{header|Yabasic}}==
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>
Note: Yabasic is an interpreter, it does not generate executables.
 
=={{header|Z80 Assembly}}==
Thanks to the Amstrad CPC's kernel, we can reduce our line count greatly by abstracting print routines to a single <code>CALL</code> statement. In addition, WinAPE lets us load our executable directly into memory without the need for a disk by simply using an <code>ORG</code> directive to define the starting address.
===With Quoted Literals===
Total: 11 lines.
<syntaxhighlight lang="z80">org &200
ld hl,g
o:
ld a,(hl)
or a
ret z
call &bb5a
inc hl
jr o
g:
db "Code Golf",0</syntaxhighlight>
 
Hexdump of the executable:
 
<code>7E B7 C8 CD 5A BB 23 18 F7 43 6F 64 65 20 47 6F 6C 66 00</code>
 
Total: 19 bytes.
 
===Without Quoted Literals===
Total: 20 lines
<syntaxhighlight lang="z80">org &200
q equ &bb5a
LD A,67
call q
LD A,111
call q
LD a,100
call q
LD a,101
call q
LD a,32
call q
LD a,71
call q
LD a,111
call q
LD a, 108
call q
LD a,102
jp q</syntaxhighlight>
 
Hexdump of the executable:
<pre>3E 43
CD 5A BB
3E 6F
CD 5A BB
3E 64
CD 5A BB
3E 65
CD 5A BB
3E 20
CD 5A BB
3E 47
CD 5A BB
3E 6F
CD 5A BB
3E 6C
CD 5A BB
3E 66
C3 5A BB </pre>
 
Total: 45 bytes.
[[Category:Simple]]
[[Category:Code Golf]]
56

edits