Solving Physical Puzzles with Ruby

Most of the time, challenges I tackle with Ruby solve code-related problems. This includes things like web services, scripts, chatbots, etc., all of which are virtual in some way. Recently though, I decided to solve a puzzle in the real world.

My son was trying to put together a wooden puzzle. It requires having four colors (blue, green, red, and yellow) each present on all four sides of a rectangle. These colors are on wooden cubes that can be rotated. So four cubes, each with six sides to rotate around. It turns out that this means there are a lot of possible combinations of these cubes, most of which won’t work. By my math, there are six sides that can face up (a “`y`” axis), multiplied by four possible rotations around that axis (`6 * 4 = 24`) for each cube. Raised to the power of the four cubes (`24^4 = 331776`). After about 30 minutes of hearing his frustration, I told him “I bet I can solve this puzzle with some code” but he was skeptical.

I took that as a challenge to both my coding skills and his respect for me as his dad, so I obliged. After finishing, I figured it would be worth sharing.