User:Lungecrunch/Q+9H test

From Esolang
Jump to navigation Jump to search

Q+9H is a derivative of HQ9+ created by User:Lungecrunch. All of the instructions are completely randomized, meaning that you will get a different result each time you run a program. For example, + may either output "Hello, world!", 99 bottles of beer, itself, or it will increment the accumulator like it usually does. This also goes for every other instruction.


Implementations

An interperter by User:Lungecrunch in Python. Heavily based off of User:Esolanger12345's implementation of HQ9+.

import random

def generate_random_order(functions, charAmount):
  B = charAmount
  A = functions

  if B > len(A):
    C = B // len(A) + 1
    D = random.sample(A * C, B)
    return D
  else:
    return random.sample(A, B)

def execute_program(commands, charAmount):
  C = 0
  D = generate_random_order('HQ9+', charAmount)

  for A in D:
    if A.lower() == 'h':
      print('Hello, world!')
    elif A.lower() == 'q':
      print(commands)
    elif A == '9':
      for B in range(99, 2, -1):
        print(str(B) + ' bottles of beer on the wall, ' + str(B) + ' bottles of beer.\nTake one down, pass it around, ' + str(B - 1) + ' bottles of beer on the wall.')
      print('2 bottles of beer on the wall, 2 bottles of beer.\nTake one down, pass it around, 1 bottle of beer on the wall.')
      print('1 bottle of beer on the wall, 1 bottle of beer.\nTake one down, pass it around, No bottles of beer on the wall.')
      print('No bottles of beer on the wall, No bottles of beer.\nGo to the store, buy some more, 99 bottles of beer on the wall.')
    elif A == '+':
      C += 1

program = input('>>> ')
charAmount = len(program)
execute_program(program, charAmount)
input()

See Also

categories r 4 real page lololo