Hexagony is a 2D esoteric language made by Martin Büttner based on hexagons. Not only the programs self are hexagons, but the memory model of terror is also based on hexagons. It took me quite some time to understand the model of terror, but eventually I still don't get it. First time I programmed in this, I was happy to get anything outputted, but after a while I realised that this is a very interesting language, with a lot to discover. I would definitely recommend programming in Hexagony.
###Length 1 snippet (try it here) !
Or in hexagon form:
!
Let's talk a bit about the memory model in Hexagony. Every memory edge has a standard value, 0
. This is different from some other models, which are standard null
. The second thing which makes this memory model different, is that the data kept in the memory edges are always numbers. No strings, lists, tuples and so on. For this program, I'm going to introduce you to the command !
. This outputs the decimal representation of the current memory edge. ;
would do the same thing, but outputs the ASCII representation.
So, you can already expect what this is going to do. This is going to print an infinite amount of 0
. After running in the online interpreter, immediately kill it. It won't stop, ever.
###Length 2 snippet (try it here)
!@
Or in hexagon form:
! @
. . .
. .
So, you might be wondering... When can you make this stop? That is done with the @
command. After reaching this point, the program terminates. That means we can now safely output one 0
with the program. Another thing you might be wondering is 'What are all those dots doing there?'. That brings us to the next command, the no-op .
. When the pointer comes to a no-op, it will not do anything and continues its way in the same direction. This means that !@
and !@...
and !@.....
are all the same and give the same output. However, if we add another dot: !@......
, this would give a bigger hexagon, since the maximum amount for a two-sided hexagon is smaller than the length of the program. It would give the following:
! @ .
. . . .
. . . . .
. . . .
. . .
###Length 3 snippet (try it here)
9!@
Or in hexagon form:
9 !
@ . .
. .
First of all, decimals in the program will be added to the current memory edge. If the memory egde = 402
and passes by a 3
, the new memory edge will contain 4023
. Same counts for letters, which replaces the memory edge with the ASCII value of the letter. I'll now explain how pointers move in Hexagony. But first of all, there isn't just one pointer. There are six. Each in every corner:
0 . 1
. . . .
5 . . . 2
. . . .
4 . 3
They all point clockwise, so 0
would go to the east (E
), the 1
would go to the southeast (SE
) and so on. The standard active pointer is 0
, and you can switch the active pointer using the [
and the ]
command. The next thing is, what happens when they get out of the board? When they leave at a non-corner point, they will enter the board again in the other half of the program (pointer starts at A
):
. . . . . F . . . A . . . . A .
A B C D E . . G . . . B . . F . . B . .
. . . . . . A . . H . . . C . . G . . . C . . G
. . . . . . . . B . . I . . . D . . H . . . . D . . H .
F G H I J K . C . . J . E . . I . . . E . . I .
. . . . . . D . . K . . J . . F . . J .
. . . . . E . . . K . . . . K .
If the pointer leaves from a corner, it depends on what value the current memory edge has (from A
to B
):
memory > 0 memory <= 0
. . A -> . . . -> B . .
. . . . . . . . . . . .
-> B . . . . . . . . A -> . . . . A ->
. . . . . . . . . . . .
. . A -> -> B . . . . .
So the order of operations in this program is 9
, !
, @
, which will output 9.
###Length 4 snippet (try it here)
!$!)
Or in hexagon form:
! $
! ) .
. .
First, it begins at the top left !
, so this will output 0
. After that, it goes to the $
, which is a jump. This will skip the next command, which is !
. So the 0
isn't outputted twice. After that, the pointer gets to the )
. This is an increment command, which just adds 1
to the current memory edge. After that, the pointer leaves the hexagon in the right corner and re-enters at the bottom left (see previous snippet to see why). As you can guess, this will output 012345678910111213141516171819202122232425...
.
After running in the online interpreter, immediately kill it, it won't stop.
###Length 5 snippet (try it here)
H;i;@
Or in hexagon form:
H ;
i ; @
. .
This one is quite easy and simple. First, the pointer gets to the H
, which pushes the char value of H
. The ;
will output the char H
. After that, when the pointer comes to the i
, the value of the memory edge will be replaced by the value of i
. This will be printed by the second ;
and terminates because of the @
.
This will output Hi
.
###Length 6 snippet (try it here)
40;);(
Or in hexagon form:
4 0
; ) ;
( .
The new thing here is that it appends two different numbers to the memory edge. After going through the 4
and the 0
, the memory edge has the value 40
. This is in ASCII (
. After that, the program will output this character and adds one up to the memory edge. That gives us 41
, which is the closing parenthese ()
). After outputting this character, the program decreases the current memory edge by 1 and goes into an infinite loop. The output will look like this: ()()()()()()()()()()...
After running in the online interpreter, immediately kill it, it won't stop.
###Length 7 snippet (try it here)
?}?"*!@
Or in hexagon from:
? }
? " *
! @
This is where the memory model of terror begins. What this does is taking 2 integers (these have to be positive or both negative), multiplies them and outputs the result. I'll explain this with the hexagonal memory model:
In the beginning, the memory model starts at the a
. The ?
pushes the input onto the memory edge a
. After that, the }
switches to the right memory edge, which is b
. There we push the input to the memory edge b
. The "
moves the memory pointer backwards and to the left, which is c
. The *
calculates the product of the two neighbours, which are a
and b
, prints it and terminates.
In pseudocode:
a = input()
b = input()
c = a * b
print(c)
end