My wife teaches elementary-school math, and I’m somewhat of a math nerd, so the 24 game is right up our alley. Basically, you’re given four numbers, and you have to find a series of operations that makes 24 from those numbers. For example, given 1, 2, 3, and 4, you might respond that 1*2*3*4 = 24. Some sets of numbers are harder than others (much harder).

One day, my wife and her class were having trouble solving a particularly hard set, so she emailed me for help. It took me a while to find the answer, and all the while I was thinking to myself “Self, I’m a programmer. Why am I doing this the hard way?” So now I’ve created the easy (cheater) way. Go to http://jebware.com/24 input your 4 numbers, and it will tell you how to make 24.

Right now it does addition, subtraction, multiplication, division, and exponentiation. However, it doesn’t understand the commutative property, so you’ll get a lot of answers that are essentially the same, like (1*2)*(3*4) and (4*3)*(2*1). I wrote it in javascript, and if you want the source or you want to improve on it, I made a repository on GitHub.

## Author: jeb

Views expressed here are my own and do not necessarily reflect the views of my employer.
View all posts by jeb

Your solver doesn’t solve (3 3 8 8) or (5 7 7 11), or those that need fractions.

8/(3-8/3) = 24

(5-11/7) * 7 = 24

Check out http://www.24theory.com, there are lots of stuff on 24 game.