Trying to Learn Hexagony
Asked Answered
P

1

5

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 . . > &

Try it online!

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

Parra answered 14/9, 2017 at 16:23 Comment(3)
For the record I managed to get a working program and reduced it in size: H;e;.i....7....y;*32;\@><.....>,<.$..Parra
I tried to improve your improvement but all I could manage was doing it without the exclamation point: H;e$$/$;y;<./6/i@., - 19 bytesParra
H;e;7i/;$,y;..$@i6< - 19 bytesParra
C
7

Here's a diagram for how the memory movement commands work:

enter image description here

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.

Cecilius answered 16/1, 2018 at 11:54 Comment(1)
Thanks! The answer I was looking for! As far as the functionality of the program above, I think I misunderstood how # works. It's been awhile since I asked the question so I'll have to review this stuff, but I'll seek you out in the chat room!Parra

© 2022 - 2024 — McMap. All rights reserved.