JavaScript (ES5), 79 bytes
b=-~!0;for(c in{Hello:a="",World:b<<=b*b})a+=c+String.fromCharCode(b++);alert(a)
Explanation
Like the other JavaScript answers, this is just a code snippet that alerts
the string'Hello World!'
.
The first trick is creating an object with the key names Hello
and World
. These are not string literals, so it obeys the rules. It is not allowed to put the exclamation mark or the space in there, so we get those characters through the second trick.
The second trick is getting the characters through their ASCII value. Sadly, we have to use String.fromCharCode
for that, which is really long. Luckily, the space (32) and exclamation mark (33) are right next to each other in the ASCII table, and the character code for the space is a nice power of 2, which is easily obtainable though bitshifting. Getting 32 using only zeroes is a little bit tricky: 32 equals 1 << 5
, which is not very golfable, but it also equals 2 << 4 = 2 << 2 * 2
. All these two's allow us to assign 2 to a variable, and use that (note that -~!0
equals 2).
The third trick is that we don't need the values in the object we loop over, and you can assign values to variables in the object declaration. This doesn't just save 2 semicolons, but also 2 dummy values, so 4 bytes in total.
JavaScript (ES6) (non-competing), 82 bytes
_=>eval('b=-~!0;for(c in{Hello:a="",World:b<<=b*b})a+=c+String.fromCharCode(b++)')
Explanation
This is a full function with the same body as the competing version, but we use a fat-arrow function with "the eval trick". eval
returns the value of the last variable it assigned to, which is a
in this case.
This is non-competing since ECMAScript 6 was released in 2015, more than 4 years after this challenge was made.
"O"*
means they can have a string literal with any number of O’s, including zero. I don’t think that was the intention. Please clarify. \$\endgroup\$