Your goal: to write a piece of code that will result in the classic result of "Hello, world!" being printed to STDOUT or equivalent.

Rules: Code must be entirely in printing ASCII. All code must be functional - removal of any single counting character must change the result or cause the code to not function. All variables must be used after assignment. Character and String literals must be necessary to the output - that is, replacement of any character literal or any character within a string literal with another character must be capable of changing the result (and not via the effect of escape sequence - replacing character with backslash or equivalent)

(NOTE: Final rule was edited in)

Scoring: This is where it gets interesting. Highest score wins as determined by number of characters, as per typical code-bowling rules. But repeated use of characters will result in point deductions. Specifically...

Repeated use of any alphanumeric character (a-z, A-Z, 0-9) will result in a deduction of 3 points per repeat (first use does not result in a deduction).

Repeated use of basic punctuation ([!?.-,":';]) - including the brackets - will result in a deduction of 2 points per repeat.

Repeated use of other ASCII characters {`~@#$%^&*_+=|\/><} - including the curly brackets - will result in a deduction of 4 points per repeat.

Repeated use of spaces, tabs, and newlines will result in a deduction of 1 point per repeat. That is, only the first use of a space, tab, or newline will count towards your total.

Note: comments do not count towards total, although the characters marking the start/end of a comment do. For instance, in C/C++, If you have /* This is a comment */, then it will count two slashes and two asterisks, but nothing between them.

Problem: The second print command will not run. Also, removing characters in quote in second print command will not change output.

x="Hello, world!";
print(x)

Problem: removal of newline will not change result or cause error (in Julia, semicolon is only necessary if multiple commands are on the same line, otherwise just suppresses return value).

print("Hellos\b, world!")

Problem: s character does not affect result, as it gets erased by \b. This is acceptable if done through code ("Hello",char(100),"\b, world!"), but cannot be done via string literals or character literals.

I created a JSFiddle where you can put your code and it will automatically figure out your score. Would you be okay with me editing a link to it it in to the post?
–
Doorknob♦Jun 4 '14 at 18:44

1

@Dennis - if your program produces a newline because of the command, no problem (for instance, println in Julia prints and then adds a newline on the end). But it shouldn't be part of the string.
–
Glen OJun 5 '14 at 3:41

1

@ACarter - basically, yes. But the restrictions and the deductions make it non-trivial.
–
Glen OJun 5 '14 at 11:56

There are no string literals here, but removal of any single character breaks the program.

Deobfuscation

There are 3 statements in this program (well, actually 2 but I abused + as some kind of statement separator)

s{}[Hel0o, w3$=d!]
This is a very stretched case of the sed operator. It is more commonly written as s/a/b/, or s:a:b:, but perl allows much more fantasy here: s(a)(b)s(a)^b^s(a)[b], and even s qaqbq.
It replaces an empty string (inside {}) with Hel0o w360d! (inside []) ($= interpolates to 60 by default). Because of the lack of an ~= operator, it operates on $_.

y<"#%&'*.124578:?@BCDEFGIJKLMNOQ/-9>(\n\t6PRSTUVWXYZ^_`abfghjmqvxz|~\cAk-u)
This is also a very stretched case, but of a tr operator, which is also called y (y< >( )).
Let's look at the replacement table:" # %&'*.124578:?@BCDEFGIJKLMNOQ /-9\n\t6PRSTUVWXYZ^_`abfghjmqvxz|~\cA k-u
I have moved some characters around so that existing string is not broken. The only actually working part here is /-9 -> k-u. It replaces 0 with l, 3 with o, and 6 with r.
Again because of lack of the ~= operator, it operates on $_
So now we have the complete phrase in the $_ variable.

I don't know Perl enough to comment on this - what is the set of characters between the < and + doing?
–
Glen OJun 5 '14 at 3:42

@GlenO Only /-9 and k-u are actually used to transform the string. The rest is an equally sized garbage. If you remove just one char, the sets will misalign and the program won't output "Hello, world!" anymore.
–
mniipJun 5 '14 at 4:26

In that case, in what way is the "garbage" being executed? That is, in what way is it functional? If it's just filler that gets jumped over by the code, then it's equivalent to non-running code within a conditional.
–
Glen OJun 5 '14 at 4:32

2

@GlenO It's not. To the spec: <...> removal of any single counting character must change the result or cause the code to not function. Removal of 1 character anywhere breaks it. You can make it work by removing 2 characters, but that's not in the rules.
–
mniipJun 5 '14 at 4:43

2

All code must be functional. You're clearly bending the rules, at the very least. I'm not saying "it breaks the rules" outright, but it's definitely questionable.
–
Glen OJun 5 '14 at 5:19

Please include the score of your code in your answer.
–
ProgramFOXJun 4 '14 at 17:24

Also it won't change your score, but the the spaces around << need to be removed.
–
Martin BüttnerJun 4 '14 at 17:30

1

Hmmm... while I do applaud your answer, it has primarily revealed a minor hole in my restrictions. I'm going to give you an upvote, and I'm happy for others to do the same if they like it, but I'll be editing in an additional restriction.
–
Glen OJun 4 '14 at 17:30

1

OK, further to my previous comment, I've now added a restriction stating that string and character literals must be relevant - replacement of characters within them must be able to change the result. This allows if 'x'>'w' techniques, but blocks "k\bH" to result in "H", for instance. Feel free to contribute a second answer following the added restriction.
–
Glen OJun 4 '14 at 17:39

When I run it in your link, it produces "Hello, world!" six times in a row. Also, what is the string of characters doing?
–
Glen OJun 5 '14 at 3:54

I'm guessing the newline is the mistake - removing it makes it work.
–
Glen OJun 5 '14 at 4:03

Copy-paste issue. There should be a tabulator right before the LF. It looks like SE won't let me do that... The string is considered a base-254 number (254b). The final result modulus 7 should be 1, so the previous code block is executed once. I'll need a modulus to make each character necessary.
–
DennisJun 5 '14 at 4:04

Well, after adding in the missing tab (which does "fix" the code), removing the Z, the T, or probably a few other characters doesn't change the result.
–
Glen OJun 5 '14 at 4:09

I had horribly misinterpreted a part of your question. It's fixed now.
–
DennisJun 5 '14 at 4:30

PHP, 1 (yes, one point!)

Using magic characters to generate a checksum, which in binary form matches "Hell", "o, w", "orld", and "! ".

Usually I like to find loopholes, but this time I decided to play by the spirit and intent of the contest. Every character and its position is essential to the output. The only places you can substitute are variable names which are not literal values, the whitespace between php and foreach which PHP treats as equivalent, and use of ' vs " which PHP treats as similar.

Ruby, 78

More rules abuse, I feel like, not sure exactly what the patch'd be. Takes a long string and checks the sum of the result, so any deletion or change will cause the program to fail. Could probably be optimized a little to remove duplication of some letters and get whitespace in there.

The problem is, everything after and including the if can be removed.
–
SiegJun 4 '14 at 20:58

@TheRare - nothing wrong with that, so long as the if does actually function and the stuff after it still obeys the rules.
–
Glen OJun 5 '14 at 11:58

@GlenO But isn't it counted as "removable code"? Just puts('Hello, world!') would work. I think the rules need clarifying if this is legit.
–
SiegJun 5 '14 at 12:53

@TheRare - in hindsight, I probably should have used a sweeping "a subset of the code should not be capable of producing the same output", but I don't think I should continue to change the rules. As they stand, as long as the code is functional and non-arbitrary, and follows the other rules, it's legitimate. At the very least, this method of solution isn't achievable in most languages (the edit I did make closed a loophole that works in most languages).
–
Glen OJun 5 '14 at 13:00

@GlenO You're the judge. Just ask me to delete these comments if you feel they're unnecessary.
–
SiegJun 5 '14 at 13:05

PHP, 2257

Loophole: the backslash was omitted from the specifications and the score calculator!

This code counts the number of occurrences of backslashes in each string and prints an ASCII equivalent. Replacing any backslash with another character, or deleting a backslash, either causes a parse error or changes the result.

A neat feature about backslashes and PHP is that they need to be escaped, so that doubles the score automatically! You can re-double, triple, etc., the score by multiplying the number of backslashes, but didn't want to be greedy, and I think it might exceed the limits of what you can enter.

It's clearly nothing more than a typo in the description, not a loophole. What's more, you knew that already. The description does explicitly say "other ASCII characters". By the time you read this, it'll have been edited to include it.
–
Glen OJun 6 '14 at 15:23

In particular, backslash was in the source of the question, but I hadn't realised that it had treated it as an escape sequence.
–
Glen OJun 6 '14 at 15:24

This isn't a change in rules, it's correcting a minor typo. The backslash was in the rules, it just wasn't displaying (to see this for yourself, click on the "edited" button, then click on "side-by-side markdown"). And the others aren't exploiting loopholes, they're exploiting features of their languages.
–
Glen OJun 6 '14 at 17:05