Author Archives: stern

Solving 24s

I am a fan of the mathematical card game “24s”, in which four cards are turned over simultaneously, and all the players search for ways to make the number 24 by combining the four numbers shown with any mathematical operators they like (I have always played with addition, subtraction, multiplication, division, powers, roots, and logarithms, but the list can be made longer or shorter depending on the preferences and mathematical skill of the players). The number on every card must be used, and no card can be used more than once. Face cards are pulled from the deck before playing and aces == 1. Suits don’t matter for the game; the deck is being used only as a random number generator.

The game is addictively fun, combining elements of math, pattern recognition, and memory. I learned the game in high school, and used to play with expedition-mates when climbing high mountains, to test for loss of mental acuity at altitude. Recently, I’ve been teaching my daughter how to play. She does pretty well!

Solutions are possible for most hands (about 83% of hands, for the normal rule set, by my computation), and in most solvable cases, more than one solution is possible. In case of a tie, cards can be distributed back to the players, or victory can be given to the newest player, or to the person who came up with the most solutions, or the most interesting solution.

Take for example the hand 2,3,10,10.

hand of cards

Two solutions are possible. The “easy” one is


But the more impressive one, remembered decades later who saw it played, is


I mention this game because I recently realized that the game is solvable, and that so long as you restrict yourself to binary operators, it is possible to determine absolutely which hands can be turned into 24 and which can’t, and how many solutions are possible for each hand, and what those solutions are.

I’ll discuss my method in future posts.

Mathematica and MySQL Server

I often use Mathematica and MySQL together; it’s typically a lot more efficient than trying to keep megabytes of data in the Mathematica notebook itself, and becomes vastly more powerful if I want to use the same data from multiple machines, all of which can tap into the same database.

Mathematica supports these uses natively, and you can send arbitrary SQL code to the server with the SQLExecute command. Interestingly, Mathematica also provides commands that map to major SQL commands, including SQLSelect[] and SQLInsert[]. I have never used these, viewing it as easier to program SQL commands in SQL itself, tuning them in MySQL Workbench.

Today, it occurred to me that Mathematica’s built-in commands might somehow be quicker than sending raw SQL, and I tested this hypothesis. Surprisingly, it turns out to be the case, with results similar to the following for a number of cases.

In[1]:= Needs["DatabaseLink`"]

In[2]:= commodDB = OpenSQLConnection[JDBC["MySQL(Connector/J)", "localhost:3306/commoddb"],
Username -> "myUsername", Password -> "myPassword"];

In[3]:= Timing[
SQLSelect[commodDB, "tbcommodprices", {"date", "ticker", "price"},
SQLColumn["ticker"] == "LAV08 Comdty" && SQLColumn["whichprice"] == "last"];]

Out[3]= {0.031, Null}

In[4]:= Timing[
SQLExecute[commodDB, "SELECT date, ticker, price FROM `commoddb`.`tbcommodprices` where ticker='LAV09 Comdty' and whichprice='last'"];]

Out[4]= {0.047, Null}

(The two queries differ slightly because I did not want caching to give an advantage to the second query).

an old motto

Last year I noticed at auction a membership certificate for the Harvard Bicycle Club dated October 12th 1883. This was, I presume the predecessor of the current Harvard University Cycling Association, for which I raced when I was young and fit.

The Harvard Cycling Team was a big deal in the years between 1879 and about 1900, and their appearance at races in New York City were regularly covered by the New York Times.

The motto of the Harvard Bicycle Club appears on the red seal affixed to the certificate. It reads

“Mobilitate viget, viresque, acquirit eundo.”
Which is from the Aenid, and can be roughly translated as

“In freedom of movement lies her power, and she gathers strength with her going.”

Sled Dogs are back again

I just got the following in e-mail.

——– Original Message ——–
Subject: Sled Dogs are back again!
Date: Mon, 24 Oct 2011 22:29:43 +0200
From: <email hidden; JavaScript is required>

Hi there,

I’m Gabor Stiglincz from We’re doing improvements for the norwegian company about the SledDogs. I’m happy to let you know, that SledDogs snowskates will be available soon worldwide. This year in Europe mostly, but now we’re testing the new prototypes, and in 2012/2013 the production will grow! Check out the latest news at and at the Facebook page:
Stay tuned, and spread the news!

Sorry about my poor english… 🙂

All the best,

Gabor /