Inspired by Advent of Code 2025, I wanted to make some kind of similar puzzle for my son. He usually takes some interest in me solving the problems. He even helped me program some solutions last year. But it mostly meant I told him what keys to press. Programming is a little hard. But he likes math.
So I came up with an idea to generate maze math problems.
Your task is to walk from start to end in a maze. You also carry a backpack with a number in it. That number is initially 1. When you cross another number on your way to the end, you add the number that you have in your backpack with the number you just encountered and put the result back in your backpack. When you cross an operator, it changes what operation you perform the next time you cross a number. The puzzle answer is the number that you have in your backpack when you reach the end.
Here is the first puzzle that I generated that I had my son solve:
######################################### # S # # ##### # ############################# # # # # ##### ######################### # # # # 4 # # ######### ##################### # # * 2 # * # + # ################# ######### # # # # 3 # # # # ######### ######### ######### # # # 4 # * # # # + # # # # ######### ##### # ##### # # # # 4 # 3 # # ############################# ##### # 2 # # 2 # ######################### # ##### # # 3 + # E # # ################################# # # # #########################################
I had to explain the rules a few times before he got it. But then he was able to solve it. It was both a little challenging to remember the number in the backpack and to remember what operation to perform. The mazes don't seem to be too hard to solve right now. Perhaps I have done something wrong in the generation code? There are often few choices that you can make.
Can you figure out the answer?
The program that generates the mazes also helpfully shows the answer and the path from start to end:
Answer = 11 ######################################### # S . # # ##### # ############################# # . . # # # ##### ######################### # # . # # . 4 . . . . . # # ######### ##################### # # . . * 2 # * # + # ################# ######### # # # # 3 # # # . # ######### ######### ######### # # # 4 # * # # # + # . # # # ######### ##### # ##### # # # # 4 # 3 . # # ############################# ##### # 2 # . . # 2 # ######################### # ##### # # 3 + # . E # # ################################# # # # #########################################
Right now only numbers 1, 2, 3, and 4 are used and operators + and *. We
can easily make the problems harder by adding bigger numbers and more
operators.
We can also get harder problems by generating mazes a few times at random. Here is one for example:
######################################### # S 2 # # ######### # ######### ############# # # # # # 3 # # # # ##### # ############# # # # # # # + * # 4 # # # # # ################# # # # # # # # 3 # # # ################# ##### # # # # 2 # # # # ############# # ##### # ##### # # 3 # + 4 # # # # ############################# ##### # # # ############################# ##### # # * # # 4 # # ##################### # # ##### # # * + # E # # # ############################# # # # 2 # ######################################### Answer = 36 ######################################### # S . 2 # # ######### # ######### ############# # # . # # . . # 3 # # # # ##### # ############# # # # # . # . . # . . + * # 4 # # # # # ################# # # # # # . . # # 3 # # # ################# ##### # # # # 2 # # # . . # ############# # ##### # ##### # # 3 # + 4 # # . . # # ############################# ##### # # . . # ############################# ##### # # * # # . 4 # # ##################### # # ##### # # * + # E # # # ############################# # # # 2 # #########################################
And of course we can play around with larger size:
################################################################################# # S * # # # # # ############# # ################# # ##### # ################# # # # # # # # # # # + # # # ################# # ############################# # ######### # # # # # 4 # # # # # ############# # ######### ##################### # # ######### # # 3 # # # # # # 4 # ######### # ######### ################# ############# ##### ######### # # # # # # # # 4 # ##### # ##################### ############# ######### # # ##### # # # * # # # 3 # # # # # ################################# # # # ################# ##### # # # # # # # # # ##### ##################### ######################### # # ##### # # # # # # # # # # # # # ##### ##### # # ##### # ##### ######### # ############# # # # # # E # # # * # # # ############# ############# ######### ##### ##################### # # # # # # 2 # # # ######### # ############# ##### # # # ######### ################# # # + # 3 # # # * # # ##### ################################# # # # # ############# # # # # # # # # # # # # ######### ######################### ############# ##### ##### # # # * # # # # # # # ############# ######################### ##### ############# ##### # # # # # # 2 # # ##### ##### ##### ############# # ##### ######### ############# # # 3 # # # # # # 4 # # # ############# ##### ##### ######### ##### ######### ############# # 4 # 3 # # 2 # # + # # # ##################### ##### ################# ##### # ##### ##### # # # # 2 # # # # ################################# # ############################# ##### # 2 + # # # # # ######################### # ################################# # ##### # # # # # # # ################################################################# ##### # # + # ################################################################################# Answer = 50 ################################################################################# # S . * . # . . . . . . # . . . # . . . . . . # # ############# # ################# # ##### # ################# # # # # . . . # . . . # . . # . . # # . . . # + # # # ################# # ############################# # ######### # # . . # . . . # # 4 . . . . . . # # . # # # ############# # ######### ##################### # # ######### # # 3 . . # . . # # . . . # . . . . # . . # 4 # ######### # ######### ################# ############# ##### ######### # # . # . . . . # . . . . # # . # # 4 # ##### # ##################### ############# ######### # # ##### # # . . # . . . * . . . # # # . . 3 # # # # # ################################# # # # ################# ##### # . # . . # # # . . . # # # # ##### ##################### ######################### # # ##### # # . # . . # . . . # . . # # # . # # # # # ##### ##### # # ##### # ##### ######### # ############# # . # . . . # # . . # . E # # # * . . # # # ############# ############# ######### ##### ##################### # # . . . # # # # 2 # . . # # ######### # ############# ##### # # # ######### ################# # . . . # + # 3 # . # . . # * # # ##### ################################# # # # # ############# # # . # # . . . . . . . . # # . . # . # # . . . # # # ######### ######################### ############# ##### ##### # # # . * . . # . . . . . . . # . . . # . . . # # . . # # ############# ######################### ##### ############# ##### # # # . . . . # . . . . . # . . # . . 2 # . # ##### ##### ##### ############# # ##### ######### ############# # # . 3 # # . . # . . . # . . # . . # 4 # . . . . # # ############# ##### ##### ######### ##### ######### ############# # . . . 4 . # 3 . # # . . . 2 # # + # . . # . . . # ##################### ##### ################# ##### # ##### ##### # # . . . . . . # # 2 # . . . # . . # # ################################# # ############################# ##### # 2 . . . . . + # # # . . # # ######################### # ################################# # ##### # # . . . . . . . # # . # # # ################################################################# ##### # # . . . . . . . . . . . . . . . . . . + # #################################################################################