Code Golf: Code Golf: Difference between revisions

m
(add task to arm assembly to raspberry pi)
 
(15 intermediate revisions by 10 users not shown)
Line 13:
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}}==
Line 179 ⟶ 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}}==
Line 231 ⟶ 283:
 
=={{header|EasyLang}}==
<syntaxhighlight>
With string literal (16 characters):
# with string literal (16 characters)
<syntaxhighlight lang="easylang">
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>
 
Without quoted literals (53 characters):
=={{header|EMal}}==
<syntaxhighlight lang="easylang">
<syntaxhighlight lang="emal">
for i in [44 0 11 10 79 40 0 3 9]write strchar 111-i.
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 261 ⟶ 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 348 ⟶ 422:
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}}==
Line 429 ⟶ 505:
 
=={{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 454 ⟶ 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 628 ⟶ 713:
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 661 ⟶ 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 (68 bytes) is:
<syntaxhighlight lang="ecmascriptwren">for(c in[37,9,2,3,70,33,9,10,0])System.write(String.fromByte(c^102))</syntaxhighlight>
{{out}}
In both cases:
56

edits