x86 machine code, 73 bytes
Inspired by Евгений Новиков's solution, I thought it should be doable with less tricks, i.e., just jumping around to otherwise "disjoint" codes for all three variants. I'm still trying with a smart variant that uses lodsb; lodsb
as central point (so only one string constant is needed for all variants)
EB 14 00 00 8A 8A 17 16 01 01 B4 B4 09 09 CD CD
21 21 CD CD 20 20 8A 1f 01 B4 09 CD 21 CD 20 48
65 6c 6c 6f 2c 20 57 6f 72 6c 64 21 00 48 48 65
65 6c 6c 6c 6c 6f 6f 2c 2c 20 20 57 57 6f 6f 72
72 6c 6c 64 64 21 21 00 00
If I recall correctly from my childhood days, COM's tiny model starts with DS=CS=SS
and the code is loaded beginning from CS:0100h
. I do not assume it is guaranteed that the code is loaded into a zeroed memory block (if it were guaranteed, I could drop two bytes).
Disassembly of the long code should be
JMP *+14h
; 20 irrelevant bytes
MOV DX,message
MOV AH,09h
INT 21h; print string pointed to by DS:DX
INT 20h; exit program
message:
DB "Hello, World!\0"
DB "HHeelllloo,, WWoorrlldd!!\0\0"
Disassembly of odd code
JMP *+00h
MOV DX,message
MOV AH,09h
INT 21h; print string pointed to by DS:DX
INT 20h; exit program
; some irrelevant bytes
message:
DB "Hello, World!\0"
Disassembly of even code:
ADC AL,00h
MOV DX,message
MOV AH,09h
INT 21h; print string pointed to by DS:DX
INT 20h; exit program
; some irrelevant bytes
message:
DB "Hello, World!\0"
2Can there be whitespace around the output? – vroomfondel – 2017-06-26T20:20:55.057
1@rogaos Sure, as long as it's the same in both variations. – Leo Tenenbaum – 2017-06-26T20:26:01.647
18Amazing first post! – Adám – 2017-06-26T22:49:17.033
11Seeing all the answers with "HHeelllloo" reminded me of speaking Whale. – Brian Minton – 2017-06-27T04:19:44.593
32Pro tip for avoiding "Hello, World!" built-ins in challenges like this: use a slightly different string of similar complexity like "Greetings, Earthlings!" – Martin Ender – 2017-06-27T07:15:16.403
1I suppose creating a Stuck program (which prints Hello World by default) with 2 ASCII NUL characters (which are both ignored by the interpreter) is considered cheating? – Daniel – 2017-06-27T09:50:38.490
1@Daniel Well it is not banned so :/ – Christopher – 2017-06-27T09:52:15.223
6"No solutions with fewer than 2 characters." Amazing. – Robert Grant – 2017-06-28T09:10:44.303
What does "take" mean? take out? keep? And I'm assuming that you are counting the newline after 'c', in your example, because you have "acdf". – veganaiZe – 2017-06-29T00:09:35.087
can there be quotes around the output? – Alexis Andersen – 2017-06-29T17:58:31.317
Honestly, I would just say "no use of 'Hello World' builtins." But I'd also add a penalty for golfing languages (or exclude them entirely), so I'm not necessarily the best person to ask. – trlkly – 2017-06-30T02:11:40.367
@trlkly Not all golfing languages have a built-in for "Hello, World!", so I think your former proposition would be a lot fairer than the latter. And to be honest, I don't think the built-ins are that much of problem either. On this challenge (at the moment) only three of the thirty answers on the first page use a built-in. – Steadybox – 2017-07-01T22:11:41.533
Is
program
purposefully excluding functions or are functions that print ok? – NonlinearFruit – 2017-07-02T01:40:16.0371
@NonlinearFruit The consensus is, that just saying
– Steadybox – 2017-07-02T02:03:23.677program
means that both full programs and functions are allowed.Golfing languages are specifically designed for small code, and thus get an unfair advantage in golfing contests. That is why I do not like them. Similarly, having a Hello World built-in also gives an unfair advantage. If we actually treated this like real code-golfing, these languages would always win. Instead we just rely on people not liking them. Objective criteria would be better, IMHO. – trlkly – 2017-07-02T07:04:46.503