Developing the Magic Hexagon Puzzle with Claude Code

We have a couple drawers in our living room coffee table with many wind-up toys and some puzzles. One puzzle has a wooden tray in the shape of a hexagonal array and 19 small hexagonal right prisms or tiles, each with an integer from 1 to 19 printed on them. The goal is to place the tiles in the tray such that each of 5 horizontal and 10 diagonal rows sum to 38.

Given a choice, and space, I prefer hands-on material objects over web apps. But this wooden puzzle or game has a couple drawbacks: there are too many pieces to keep track of, and one has to mentally recompute the rows sums over and over. It looked like a good condidate for a web app.

Around this time, my subscription to the Claude AI desktop app came to include the Code tab as well as the Chat tab. In the Chat tab, you can write prompts to ask general questions and to generate code from snippets to complete web pages. The code for a web page resides in and can be viewed and displayed by Chat in a local browser pane. In contrast, the Code tab can also write and edit a project consisting of multiple files on your disk. That allows you to develop complex projects. And having the code on your computer lets you make changes in the code file directly yourself, after which Code can reload it and continue working on it.

I decided to use Claude Code to develop a web app version of the puzzle, the Magic Hexagon Puzzle. My work spanned three days of part-time work to get a web app that works and looks well. Most work with Code involves writing prompts, which are written descriptions of what I would like Code to do for me.

This is the start of the first prompt I wrote: “I want you to develop a web app that is a “magic square” game (although no squares are involved!) – the game involves moveable hexagonal pieces, each numbered with one unique number in the range 1 to 19 – the game also involves a hexagonal target array of hexagonal target locations, where the target locations are the same size as the moveable pieces and the hexagonal array has 19 locations (each of the 6 sides of the array is 3 locations long)…

In the first day, Code quickly got the major components working. I was very impressed. It did have a problem in that some of its logical rows to sum had “kinks.” I first tried to write prompts to solve this problem but found that it was more effective to go into the Javascript file myself and edit the arrays that defined the rows. I was helped by the comments which Code had written in the file that showed graphically the tile layout in the hex array.

Another help was that Code created, without being asked, a new screen coordinate system with integer increments of the width of a tile. This made it easy for me to specify locations. Code then had a function to convert from these coordinates to screen pixel coordinates, which are useful for small adjustments but not intuitive for layout design.

Adding the row sum indicators was pretty straightforward, first asking for a function to make a single circle with a field for a row sum and an arrow whose angle could be specified. Then I asked for an indicator to be placed just outside the end of each row. Most time was spent getting the indicators placed and arrows pointing correctly.

Most of the last two days of development involved adjusting sizes and positions of elements. This took more of my time than having Code get the major elements on screen and the functionality working. For questions on issues related to the project, I switched to Chat mode.

In conclusion, I was very impressed with Claude Code! Having the ability to edit code by hand in Code is an advantage over developing a project in Chat where you can’t edit the code in a project directly during development but must keep writing prompts.

Please send us a message letting us know what you think at support@reactorlab.net