Shortest Sorted Hello World
///, 7 lines, 22 bytes
/
//Hello
,
Wor
l
d
!
A rare chance for /// to be competitive (well as long as no one starts with Unary and Lenguage...).
The code first encounters a /
, and parses the
/
//
as a substitution instruction which removes all newlines from the remainder of the program. Afterwards, the program merely reads
Hello, World!
which is printed verbatim as it doesn't contain any further slashes.
Headsecks, 1 line, 366 bytes
$(((((((((((((((((((((((((((((,000000044888<AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADIIIIIIIIIIIILPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPTXXXXXXXXXXXXXXXXXXXXXXXX\```diiiiiilqqqqqqqqtyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy|
Headsecks is a trivial Brainfuck substitution where the only thing that matters is the code point modulo 8. The equivalent Brainfuck is merely
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++++++++.+++++++..+++.-------------------------------------------------------------------.------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++++++++++.+++.------.--------.-------------------------------------------------------------------.
Luckily this naive approach just fits. There's some potential for golfing down bytes, but it might be hard.
Tested using this Python interpreter.
Generating code
code = "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++++++++.+++++++..+++.-------------------------------------------------------------------.------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++++++++++.+++.------.--------.-------------------------------------------------------------------."
command_map = "+-<>.,[]"
last_point = 32
out = []
for char in code:
curr_mod = command_map.index(char)
last_mod = last_point % 8
if curr_mod > last_mod:
last_point += curr_mod - last_mod
elif curr_mod < last_mod:
last_point += (8 - last_mod) + curr_mod
out.append(chr(last_point))
print("".join(out))
JavaScript (67 66 62 lines, 227 269 bytes)
(Note: only tested on Firefox 36 and Safari 8, contains minor ES6 features (the Set
class))
Z
=
!""+
(0[[]]
+
(
!!""+Set
));c
=Z[~
-22]
$=Z[
3]
$$=Z[
15]
$$$=Z[
24]
$$$$=Z[
1]
$$$$$=Z[
0]
Set
[c
+
$$$+Z[
5]
+Z[
16]
+
$$$$$+
$$$$+Z[
2]
+c
+
$$$$$+
$$$+
$$$$]
(Z[
14]
+
$$+
$+
$$$$+
$$$$$+
"(\
'H\
"+
$+
$$+
$$+
$$$+
",\
W\
"+
$$$+
$$$$+
$$+Z[
6]
+
"\
!')\
")
()
The code above basically does:
alert("Hello, World!")
Obviously alert
is not sorted. So instead we need to generate the statement as a string, and "eval" it:
s = "alert('Hello, World!')"; // generate this using sorted code
eval(s)
How to generate the string? ES5 supports line continuation so that
"AL\
ERT" === "ALERT"
But the character code \
appears before all lowercase letters, so we have to generate the lowercase letters using other methods.
We borrow some idea of JSFuck here. The lowercase letters involved in the alert statements are:
t e r a o l d
all of these can be extracted from characters of standard objects, which may be expressed in terms of some sorted sequence:
t, e, r ← true = !""
a, l ← false = !!""
o ← function = Set
d ← undefined = 0[[]]
How do we evaluate the string? Surely we cannot use eval(s)
as it is not sorted. Alternatively we could use Function(s)()
, but we cannot use Function
as it is not sorted either. However, Function
is the constructor of all functions, which means Set.constructor === Function
.
Adding the identifier constructor
makes the list of lowercase letters become:
t e r a o l d c u n s
which fortunately could still be generated by "truefalseundefinedfunction"
:
t, e, r, u ← true = !""
a, l, s ← false = !!""
o, c, n ← function = Set
d ← undefined = 0[[]]
After prettifying, the code above should read like:
// lines 1~8 defines our string containing all lowercase letters we want
Z = true + (undefined + (false + Set))
// Z = "trueundefinedfalsefunction Set() { [native code] }"
// lines 8~20 defines the variables `c`, `$` (e), `$$` (l), `$$$` (o),
// `$$$$` (r), `$$$$$` (t)
// for the corresponding lowercase letters extracted from `Z`
// the rest calls:
Set["constructor"]("alert('Hello, World')")()
// lines 22~36 generates the "constructor" string
// lines 37~61 generates the "alert('Hello, World')" string
Update: Renamed E
, L
, O
, R
, T
to various repetition of $
to reduce 4 lines.