HQ9+
Jump to navigation
Jump to search
HQ9+ is a joke language with four instructions:
- H: Print "hello, world"
- Q: Print the program's source code
- 9: Print the lyrics to "99 Bottles of Beer"
- +: Increment the accumulator
Although the language is not of serious interest by itself, it can be useful to implement HQ9+ in a new esoteric programming language, since doing so proves that all the tasks above, except the quine, are possible. HQ9+ was created in 2001 by Cliff L. Biffle.
Implementation
User:A was here and here is the implementation(in C):
#include <stdio.h> int main() { unsigned long accumulator = 0; char c[1000]; for(int i=0;;i++) { scanf("%c",&c[i]); if(c[i]=='\n') break; } for(int i=0;c[i]!='\0';i++) { if(c[i]=='H') printf("Hello, World!\n"); else if(c[i]=='Q') printf("%.*s", (int)sizeof c, c); else if(c[i]=='9') { for(int i=99;i>0;i--) { printf("%d bottles of beer on the wall,\n%d bottles of beer.\n", i); printf("Take one down, pass it around,\n%d bottles of beer on the wall.", i-1); } printf("1 bottle of beer on the wall,\n1 bottle of beer.\nTake one down, pass it around,\nno more bottles of beer on the wall."); } else if(c[i]=='+') accumulator++; } return 0; }
Lanmonster fixed the Q instruction and added the + instruction
See also
- HQ9++, an object-oriented extension of HQ9+.
- HQ9+-, an extension of HQ9++ with the - operator for debugging purposes.
- HQ9+~, and extension of HQ9+ which is Turing-complete.
- HQ9F+, an extension of HQ9+ with the F operator for FizzBuzz.
- FHQ9+-, an extension of HQ9+- with the F operator for FizzBuzz.
- CHIQRSX9+, another HQ9+ extension supposedly Turing complete.
- HQ9+B, an ℒ-complete extension of HQ9+.
- HQ9+2D, a 2-D extension of HQ9+.
- H9+, with one fewer instruction but still capable of all of the tasks.
- FISHQ9+, HQ9+ and deadfish combined.
- HI9+, which replaces Q with an instruction that prints the interpreter's source code.
- +, where there is only +, and other characters are ignored.
- Hq9eFuck, HQ9+, brainfuck and Deep Thought combined.
- BrainfisHQ9+ HQ9+, brainfuck and deadfish combined.
External resources
- HQ9+ home page (from the Wayback Machine; retrieved on 2 June 2009)
- HQ9+ as an embedded language in Haskell
- Online HQ9+ interpreter in JavaScript
- Online HQ9+ interpreter realized with PHP
- HQ9+ interpreter in C by User:mmphosis
- HQ9+ interpreter in Pascal by User:GrandKeyboard
- hq9plus - HQ9P implementation for Parrot
- HQ9+ Interpreter - HQ9+ interpreter written in Kotlin by User:Timleg002