H

From Esolang
Jump to navigation Jump to search

Note that h is typically lowercased.

h is a programming language created by Nerdaxe#9443 which is extremely limited.

Every program is an arbitrarily long but finite list of unbounded integers, separated by commas. The accumulator and index of the current cell are set to 0 initially; cells are 0-indexed.

Say that the accumulator is A, the index of the cell being pointed to by the IP is C and i(n) is the value of the nth cell. The operation order:

  • A is set to i(i(C)) - A
  • i(i(C)) = A
  • if A is negative, C becomes i(C+1), otherwise C becomes C+2

Execution ends when the instruction pointer goes to an index larger or smaller than the largest/smallest index in the list, respectively.

Sample programs

20,2,19,4,7,6,7,0,19,10,21,12,15,14,15,0,18,-1,-1,0,A,0

A is a placeholder for any integer. This program will eventually print

20,2,19,4,7,6,7,0,19,10,21,12,15,14,15,0,18,-1,-1,-A,A,A

Hello, World!

A strict version of the Hello, World! program is technically impossible, because all output is a list of numbers.

Infinite Loop

8,2,9,4,9,6,8,2,-1,0

By VilgotanL, explanation using pseudo-code similar to subleq assembler:

neg1 2 #acc is now -1
zero 4 #acc is now 1, the variable zero is 1
zero 6 #acc is now 0, the variable zero is 0
neg1 2 #acc is now -1, go back to 2
neg1:-1 zero:0 #variables

Quine

1,-1

Computational class

The computational class of h is unknown. A variant, h2, was created by User:Andrew3335 in the hopes of being a suitable Turing-complete replacement if h itself is not turing complete. The only deviance from h in h2 is that the list of integers that serves as the initial program is assumed to have an infinite amount of 0s appended to its end, such that the only way to end execution is now for the instruction pointer to go to a cell whose index is smaller than 0.

Implementation

a=0
p=0
m=[]
while -1<p:
    a=m[m[p]]-a
    m[m[p]]=a
    if a<0:p=m[p+1]
    else:p+=2
print (m)

Heavily golfed Python 3 program by Nerdaxe.