HZCode

From Esolang
Jump to navigation Jump to search

HZCode or HZC is perhaps the first 2-Dimensional esolang based on Chinese characters. It is invented by User:None1. It is inspired by Aheui, and derives a lot of commands from Befunge. Like Aheui, it doesn't have self-modifying.

Pronounciation

HZ comes from 汉字, the Chinese word meaning Chinese characters (Hanzi), so it should be pronounced /'hɑːnzkəud/, but saying the H and Z as individual English letters is fine.

Memory

It uses two stacks containing unbounded unsigned integers, and a queue containing instruction pointers. There is an instruction pointer that points to the top-left and faces to the right initially, and the stacks are empty. Popping from an empty stack returns 0. Subtraction from 0 returns 0 and division or modulo by 0 returns 0.

Unlike Befunge-93, it has no restriction on code size.

Execution

From now on, when we mention IP, we mean the instruction pointer at the queue front.

  1. Read the character at the IP.
  2. Execute the character.
  3. Pop the IP, move it in its direction (up/down/left/right) and push into the queue back, then repeat 1.

Moving out of bounds wraps around.

Commands

Movement

Command Meaning
Set IP direction to up
Set IP direction to down
Set IP direction to left
Set IP direction to right
Do nothing, usually used to make the code prettier

Rotation

Command Meaning
Rotate IP 90 degrees clockwise if top of first stack isn't 0, otherwise rotate 90 degrees counterclockwise
Rotate IP 180 degrees if top of first stack isn't 0

Jump

Command Meaning
Pop b and a from first stack, jump to coordinate (a,b) (means (b+1)-th character from the left in (a+1)-th row from the top)
Nothing executed until next 移 (like Funge-98's semicolons)

Queue operations

Command Meaning
Pop c, b and a from first stack, create an instruction pointer at (a,b) that faces the direction of c modulo 4 (0:right 1:down 2:left 3:up) and push it into queue back, each IP has its own stacks
Pop the IP out of queue, if the queue is empty after this operation, the program stops

Stack operations

Command Meaning
Pop first stack and push it into the second stack
Pop second stack and push it into the first stack
Swap the content of the first stack with the second stack
Pop first stack and discard
Duplicate top of first stack

I/O

Commnd Meaning
Input as integer and push into first stack
Output the top of first stack as integer
Input as Unicode and push into first stack
Output the top of first stack as Unicode

Note: the output commands don't discard the stack top, EOF results in 0.

Arithmetic

Command Meaning
Increment top of first stack
Decrement top of first stack
Pop b and a from first stack, push a+b onto first stack
Pop b and a from first stack, push a-b onto first stack
Pop b and a from first stack, push a×b onto first stack
Pop b and a from first stack, push a÷b (floor division) onto first stack
Pop b and a from first stack, push a mod b onto first stack
Push a random number between 0 and 1 onto first stack

Constants

The characters

零一二三四五六七八九十百千万亿兆

Push 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, 1000, 10000, 100000000, 1000000000000 onto the first stack respectively.

Other characters are NOPs.

Examples

XKCD Random Number

四说停

Truth Machine

下空右说停空
右听分下空左
空空右右说上

Shorter version:

听右说反停

A+B Problem

听听加说停

Multi-IP test

下百十一加加写停
右零一零双百写停

The original IP creates another IP at (1,0), facing right, then prints d, then the IP created by the original IP prints o (it prints after the original IP because the original IP hits 写 first).

Fork bomb simulator

The original IP creates another IP at (0,0), facing right, then the original IP and the IP it created create other IPs.

Since HZCode doesn't use real threads, one IP is created per run, so it is not as dangerous as real fork bombs.

Infinite repeating cat program

读写

Note that the IP wraps around when out of bounds.

Cat program

下空停空空
右读分空空
空空右写下
上空空空左

Unoptimized Hello, World!

十十十十十十十一一加加加加加加加加写百一加写百一一一一一一一一加加加加加加加加写百一一一一一一一一加加加加加加加加写百 十一加加写十十十十一一一一加加加加加加加写十十十一一加加加加写十十十十十十十十一一一一一一一加加加加加加加加加加加加加加写百十一加加写百十一一一一加加加加加写百一一一一一一一一加加加加加加加加写百写十十十一一一加加加加加写停

Coin (In Chinese)

下空右万万千百百百百十十十十十一一一加加加加加加加加加加加加加加写空空空空空空空空空空空空空空空空停
右随分空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空
空空右万万千千千千千千千百百百百十十十十十十十十十一加加加加加加加加加加加加加加加加加加加加加加写停

Infinite DNA Code

随二乘随加一加零跳空空空空空空空空空空空空空
十十十十十十五加加加加加加写去零零跳空空空空
十十十十十十十十四加加加加加加加加写去零零跳
十十十十十十七加加加加加加写去零零跳空空空空
十十十十十十十一加加加加加加加写去零零跳空空

Pi calculator (slow)

Outputs an approximate value of pi (3.136) using a very stupid method. Also, this doesn't output any decimal points, so the actual output is 3136.

右升空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空下
下升升升升升升升升升升空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空左
右升升升升升升升升升升升升升升升空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空下
下升升升升升升升升升升升升升升升升升升空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空左
右升升升升升升升升升升升升升升升升升升升升空空空空空空空空空空空空空空空空空空空空空空空空空空空空空空下
下升升升升升升升升升升升升升升升升升升升升升升空空空空空空空空空空空空空空空空空空空空空空空空空空空空左
右升升升升升升升升升升升升升升升升升升升升升升升升空空空空空空空空空空空空空空空空空空空空空空空空空空下
下升升升升升升升升升升升升升升升升升升升升升升升升升升空空空空空空空空空空空空空空空空空空空空空空空空左
右升升升升升升升升升升升升升升升升升升升升升升升升升升升升空空空空空空空空空空空空空空空空空空空空空空下
下升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空空空空空空空空空空空空空空空空空空空空空左
右升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空空空空空空空空空空空空空空空空空空空下
下升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空空空空空空空空空空空空空空空空空空左
右升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空空空空空空空空空空空空空空空空空下
下升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空空空空空空空空空空空空空空空空左
右升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空空空空空空空空空空空空空空空下
下升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空空空空空空空空空空空空空空左
右升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空空空空空空空空空空空空空下
下升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空空空空空空空空空空空空左
右升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空空空空空空空空空空空下
下升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空空空空空空空空空空左
右升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空空空空空空空空空空下
下升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空空空空空空空空空左
右升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空空空空空空空空下
下升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空空空空空空空左
右升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空空空空空空空下
下升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空空空空空空左
右升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空空空空空空下
下升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空空空空空左
右升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空空空空空下
下升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空空空空左
右升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空空空空下
下升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空空空左
右升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空空空下
下升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空空左
右升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空空下
下升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空空左
右升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空下
下升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空左
右升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空下
下升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空左
右升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升空下
下升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升左
右升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升下
下升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升左
右升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升下
下升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升左
右升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升下
下升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升左
右升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升下
下升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升升左
右四四乘乘说停

Inspired by a pi computing program in Piet.

See also

External resources