31
6
The goal of this code golf is to create an interpreter for the programming language HQ9+
There are 4 commands in this programming language:
- H - prints "Hello, world!"
- Q - prints the source code of the program
- 9 - prints the lyrics of the song "99 bottles of beer"
- + - increments the accumulator
The rules:
- Because the accumulator isn't defined, you can ignore the command +
- Your program should prompt for input (this input will be the source code) or the source code is read from a file
- You are not allowed to put the lyrics of "99 bottles of beer" in a file, and read the text from the file
- You are not allowed to use a compression algorithm such as GZip or BZip to compress the song text: you have to create your own compression algorithm. This doesn't have to be a complex algorithm, but try to compress the text as much as possible (remember: this is a code-golf, the code with the fewest bytes wins)
- If the source code contains a char that isn't H, Q, 9 or +, then output "Source code contains invalid characters" before running any commands! This means that, if the source code is
H1
for example, then don't outputHello, world!
before you outputSource code contains invalid characters
. No, immediately outputSource code contains invalid characters
- If your interpreter accepts both uppercase and lowercase characters, then you get -8 to your character count
Good luck!
2An interpreter in HQ9+ should automatically win. – TheNumberOne – 2015-01-03T22:51:39.770
No because it doesn't accept input – Oliver Ni – 2015-01-04T17:25:34.393
4Rule 4 doesn't make sense at the "why would he prohibit that?!" level; rule 5 doesn't make sense at the "what does he mean?!" level. – Peter Taylor – 2013-10-22T18:44:27.590
4How does rule 5 not make sense? – Mike C – 2013-10-22T19:37:31.910
I think it would be better to just require it only uses uppercase, rather than arbitrarily saying you get a free 8 characters off if it accepts either. 8 may or may not cover it depending on the language. – Mike C – 2013-10-22T22:37:53.837
12Rule 5 does not make sense because it breaks the HQ9+ spec. – boothby – 2013-10-23T02:27:25.933
@boothby: OK, I removed that rule. – ProgramFOX – 2013-10-23T15:26:16.243
@MikeC, it said what you must not do, but it wasn't clear to me that it fully stated what you must do. – Peter Taylor – 2013-10-23T20:06:19.627
do I get extra points if it accepts uppercase
+
? – 12Me21 – 2017-02-11T16:49:32.443