Prototyping a math puzzle with Soffit

in #puzzle6 years ago (edited)

Can you find a path in the following graph that sums to 100? When you follow a blue edge, you add the number, and when you follow a red edge, you must subtract the number. So, starting at 13 and following across the top edge gives 13 + 5 - 9 + 7 - 11 = 5.

mathpuzzle-example-1.png

Need a hint? This version of the puzzle has the same solution!

mathpuzzle-example-2.png

I'm trying to use Soffit, my graph grammar engine, to generate puzzles or mazes, and this is my first prototype. It places a single fixed solution on the grid, and then fills in all the other nodes and edges randomly. Unfortunately, this is kind of tedious in Soffit right now because the language lacks wildcarding, so I wrote some Python code to generate tons of rules like this:

    ...
    "A--B; A[1]; B[7]" : ["A--B [+]; A[1]; B[7]", "A--B [-]; A[1]; B[7]"],
    "A--B; A[1]; B[8]" : ["A--B [+]; A[1]; B[8]", "A--B [-]; A[1]; B[8]"],
    "A--B; A[1]; B[9]" : ["A--B [+]; A[1]; B[9]", "A--B [-]; A[1]; B[9]"],
    "A--B; A[1]; B[10]" : ["A--B [+]; A[1]; B[10]", "A--B [-]; A[1]; B[10]"],
    "A--B; A[1]; B[11]" : ["A--B [+]; A[1]; B[11]", "A--B [-]; A[1]; B[11]"],
    "A--B; A[1]; B[12]" : ["A--B [+]; A[1]; B[12]", "A--B [-]; A[1]; B[12]"],
    "A--B; A[1]; B[13]" : ["A--B [+]; A[1]; B[13]", "A--B [-]; A[1]; B[13]"],
    "A--B; A[1]; B[14]" : ["A--B [+]; A[1]; B[14]", "A--B [-]; A[1]; B[14]"],
    "A--B; A[1]; B[15]" : ["A--B [+]; A[1]; B[15]", "A--B [-]; A[1]; B[15]"],
    "A--B; A[1]; B[16]" : ["A--B [+]; A[1]; B[16]", "A--B [-]; A[1]; B[16]"],
    "A--B; A[1]; B[17]" : ["A--B [+]; A[1]; B[17]", "A--B [-]; A[1]; B[17]"],
    "A--B; A[1]; B[18]" : ["A--B [+]; A[1]; B[18]", "A--B [-]; A[1]; B[18]"],
    "A--B; A[1]; B[19]" : ["A--B [+]; A[1]; B[19]", "A--B [-]; A[1]; B[19]"],
    "A--B; A[1]; B[20]" : ["A--B [+]; A[1]; B[20]", "A--B [-]; A[1]; B[20]"],
    "A--B; A[2]; B[0]" : ["A--B [+]; A[2]; B[0]", "A--B [-]; A[2]; B[0]"],
    "A--B; A[2]; B[1]" : ["A--B [+]; A[2]; B[1]", "A--B [-]; A[2]; B[1]"],
    "A--B; A[2]; B[2]" : ["A--B [+]; A[2]; B[2]", "A--B [-]; A[2]; B[2]"],
    ...

This method unfortunately doesn't guarantee that the solution is unique!

What I would like to do as the next stage of prototyping is generate the solution as well, by starting with something like

"A[0]; B[100]; A--B[+];"

and then iterating with rules that add extra steps to the solution, or move values around in the chain of nodes that constitute a solution. It might be better to generate a solution with a different grammar first, and then place it on a grid as a separate step. Or, it might work better to start with something like 10--10--10--10--...--10 and mutate from there rather than initializing with one big step.

Source code for the initial placement of the solution on the puzzle grid (spoiler alert!): https://github.com/mgritter/soffit/blob/a0d3cce0325a2b97db088e5e3f7db1742ab5f83d/doc/examples/mathpuzzle.json

Sort:  

13-0+19+1+18-5+20+15+19=100

Congratulations @markgritter! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You received more than 7000 upvotes. Your next target is to reach 8000 upvotes.

Click here to view your Board of Honor
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard:

Meet the Steemians Contest - The results, the winners and the prizes
Meet the Steemians Contest - Special attendees revealed
Meet the Steemians Contest - Intermediate results

Support SteemitBoard's project! Vote for its witness and get one more award!

Coin Marketplace

STEEM 0.18
TRX 0.16
JST 0.030
BTC 62663.38
ETH 2445.34
USDT 1.00
SBD 2.67