Hexar

From Esolang
Jump to navigation Jump to search

Hexar is an esoteric programming language which uses almost only hexadecimal numbers created by Enchant3d.

Language overview

Hexar runs on an array that can contain only positive numbers (up to 10000). Each hexadecimal number written in the language must be surrounded by parentheses, brackets, braces or signs less than and more than to show what the number is used for (change a number in a cell of the array, change the pointer and others ...). Hexar also uses other characters that can display a number, increment a cell, request an input etc... Commands are:

Characters Description
[] The number between these two characters is the pointer of the array
() The number between these two characters is the cell under the pointer
{} The number between these two characters is the line which the program goes to if the cell under the pointer is not equal to 0
<> looks like the if condition, if the cell under the pointer is greater than the cell before the cell under the pointer, the program goes to the line between the two characters
= Output the number in the cell under the pointer in decimal
: Output the character signified by the ascii code of the cell under the pointer
, Output the number in the cell under the pointer in hexadecimal
+ Increment the number in the cell under the pointer
- Decrement the number in the cell under the pointer
? Put number from user (in decimal) in the cell under the pointer
! Put random number from 0 to the cell under the pointer to the cell under the pointer
; End a line (useful for comments)

Examples

Hello, world!

[0] (48);                                    //store number 48 (72 in decimal) in cell 0, ascii code of 'H'.
[1] (65);                                    //e
[2] (6C);                                     //l
[3] (6C);                                    //l
[4] (6F);                                    //o
[5] (2C);                                    //,
[6] (77);                                    //w
[7] (6F);                                    //o
[8] (72);                                    //r
[9] (6C);                                    //l
[A] (64);                                    //d
[0]:[1]:[2]:[3]:[4]:[5]:[6]:[7]:[8]:[9]:[A]:; //output characters from cell 0 to cell 10

Addition

[0]?;                                       //input the the first number in cell 0
[1]?;                                       //input the second number in cell 1
[1]-[0]+[1];                                //decrement the cell 1 and increment the cell 0 and set the pointer to cell 1
{2};                                        //goes to line 2 (line 3 because the first line is line 0) until cell 1 is not equal to 0
[0]=;                                       //output cell 0 (sum)

Multiplication

[0]?;                                       //input the first number in cell 0 (factor 1)
[1]?;                                       //input the second number in cell 0 (factor 2)
[1]-[2]+[3]+[1];                            //decrement cell 1, increment cell 2, increment cell 3, set the pointer to cell 1
{2};                                        //goes to line 2 until cell 1 is not equal to 0
[3];                                        //set the pointer to cell 3
-[1]+[3];                                   //decrement cell 3, increment cell 1, set the pointer to cell 3 again
{5};                                        //goes to line 5 until cell 3 is not equal to 0
[0]-;                                       //decrement cell 0
{2};                                        //goes to line 2 until cell 0 is not equal to 0
[2]=;                                       //output cell 2 (product)

Less or more

[64] (6C);                                  //l
[65] (65);                                  //e
[66] (73);                                  //s
[67] (73);                                  //s
[68] (6D);                                  //m
[69] (6F);                                  //o
[6A] (72);                                  //r
[6B] (77);                                  //w
[6C] (69);                                  //i
[6D] (6E);                                  //n
[3] + [1] (14)! ;                           //add 1 to cell 3 select a random number between 0 and 20 to cell 1
[1]-[2]+[4]+[1];                            //decrement cell 1 and put the random number in cell 2 and 4
{B};                                        //goes to line B if cell 1 is not equal 0
[2] {11};                                   //select the pointer at cell 2 and go to line 11 (skip line to say less and more)
[64]:[65]:[66]:[67]:;                       //output "less"
[2] {11};                                   //select the pointer at cell 2 and go to line 11 (skip line to say more)
[68]:[69]:[6A]:[65]:;                       //output "more"
[3]-;                                       //decrement cell 3 (line to reset the input)
{11};                                       //goes to line 11 if cell 3 is not equal to 0
[0]?;                                       //input the number to guess
[0]-[3]+[0];                                //move the input from cell 0 to cell 3
{14};                                       //goes to line 14 if cell 0 is not equal to 0
[3] <E>;                                    //if input is greater than the number to guess, goes to line E
[4] <10>;                                   //if input is smaller than the number to guess, goes to line 10
[6B]:[6C]:[6D]:;                            //output win