C plus plus programming and other negative effects of the pandemic
By Bobby Neal Winters
They say that Isaac Newton invented calculus and put together his theory of gravity during a pandemic. I learned another computer language and beat the peg puzzle. Here is how that goes.
You might have seen the peg puzzle at a pizza place or a bar. It is typically a small piece of wood that is an equilateral triangle if you ignore its thickness. It has holes drilled in it and the holes are arranged in rows. In the top row there is on hole; in the second two; this goes on down to the fifth row which contains five holes. All together, there are 15 holes.
Into these holes, you put 14 pegs. Usually you fill every hole but the middle hole in the third row. The idea is that you jump pegs and remove them and you try to get to as few pegs possible. If you only have one peg, you win.
I’ve got one that was given to me by my father-in-law. I’ve got it sitting on my computer to my right as I write this. I don’t remember how long ago he gave it to me, but I do know he’s been dead for 13 years. I suspect he gave it to me with the expectation that since I am a math guy, I would solve it.
Well, I have but that has been more than a decade in the making.
The story goes like this. I cleaned out my garage this summer as a part of my COVID cleaning. Not being able to go anywhere led to me having a bit of pent up energy. Couple this with the fact that I decided to get a freezer for my garage to put a beef in (whenever the local butchers catch up that is!) and the garage got cleaned more deeply than it had for a long, long time.
In my cleaning and rearranging, I found the puzzle. There it was, unconquered. It had a decade worth of dust and spiderwebs on it. But it made me remember.
What happens next might not be what you expect. I put it on the back porch to let it get rained on for a while, and I came into the house and started the process of writing a computer program to solve it.
I’ve been learning C++. There aren’t many of you out there who really care about computer programming, so I will speak in metaphors. Have any of you seen the old PBS show “The Wheelwright’s Shop”? The guy makes furniture, and when he is going to make a chair, his first step is to take an iron fencepost to the forge and make a tool with it that he will eventually use to shape an old log he found in the woods.
That is what programming in C++ is like: You have to make the tools before you make the pieces, and then you put it together.
This is what I began the process of doing. For those of you who are interested, I modeled the game with a 15 bit binary number. There are only certain ways you can move between the numbers. You program the computer to make the moves and then you stop when you can’t move anymore. Then you check how many pegs are left. If there is only one, you win; otherwise, backup and do it again, keeping track of the ways that didn’t work.
For those of you who are interested, there are 89 different ways that the game can end. There is exactly one of those where a single peg is left. Moreover, there are a lot of different ways to get to each of the 88 ways that are losers: more than 130 thousand.
So what I could do would be to memorize the 13 jumps it takes to win, but that doesn’t seem right. I suppose the best way would be to learn strategy.
That might have to wait for another pandemic.
Bobby Winters, a native of Harden City, Oklahoma, blogs at redneckmath.blogspot.com and okieinexile.blogspot.com. He invites you to “like” the National Association of Lawn Mowers on Facebook. )