I'm trying to wrap my head around the programming language Hexagony. I've looked at a few sample programs and have tried writing a simple program to read input and print Hey [input]!
. Here's what I have.
, < . . C $
. . { . # . ;
. . . # . . 2 '
. . . . # C 3 < .
. # . # . . * . ; .
. E . . E . ; . . > /
= . . . } y . . 3 .
. . . . ; . . 3 .
. . . e $ . ; .
. . ; . . @ .
. H . . > &
If there is no input it prints Hey !
as expected. But with any input it prints EE!
. I'm pretty sure my issue is I don't understand how the memory pointers work on the hexagonal grid. I'm assuming my code has issues with over writing values if the input is too many string but I'm not concerned with that as of yet. I confused as to the exact rules for which edge is selected with the {
and }
commands and how the direction of the MP is affected with this.
If anyone could give me a more explicit explanation of how the memory works how the MP is oriented with a shift that would be appreciated
Here's a diagram for how the memory movement commands work:
The memory pointer (MP) has a position (which is an edge of the memory grid) and an orientation along that edge. In the diagram, the initial position of the MP is marked with the red arrow, so it currently points north.
The MP movement commands are always relative to the current position and orientation of the MP. I've annotated the four adjacent edges based on which command gets you there. So {
moves the MP forward and to left, and '
moves it backward and to the right, for example.
To figure out its new orientation, you can think of this movement as rotating the MP by 60 degrees about one of the adjacent hexagons. So depending on the chosen command, the MP would point in the following directions for the above diagram:
Cmd Orientation
{ north west
} north east
" north east
' north west
Also, just in case this is part of the confusion, remember that the memory grid is independent of the source grid (so these are not the edges of the grid containing the commands... it's just a separate, and infinite, hexagonal grid).
As for your actual program, it seems to have bigger issues than memory layout. Most of all, I'm not sure what those #
are doing in there: #
switches to one of the 6 IPs based on the current memory value modulo 6. Assuming your input is arbitrary, this basically switches you to a random IP, which is probably not what you want.
I can highly recommend trying out Timwi's EsotericIDE (which I also used to generate the diagram above), which allows you to step through the program and includes a visualisation of the memory grid.
I'm also happy to help you in this SE chat room if you have any further questions about the language.