Oct 6, 2008 10:06 AM
| Last Modified: Jul 12, 2019 7:18 AM
This blog post was written by a blogger who is no longer at SAS
My friends and co-workers know me as quite the little francophone. I travel to France as often as I can. I'm currently working on a master's degree on the subject at North Carolina State University. And I hoard every French newspaper and magazine that I get my hands on.
Le Figaro is a daily paper that adds a supplement, Le Figaro Magazine to its Saturday edition. There you find art news, columnists, and my favorite: games.
I'm consistently amazed at how the French make games simply out of things we consider dramatically un-fun. For example, one the games in the magazine relates to a letter from Blaise Pascal to his brother, where you have to (a) complete the letter with 16 given words; (b) correct 16 spelling or language errors; and (c) find 15 anomalies, anachronisms, or historical impossibilities.
One of the number games jumped out at me (pun intended). Here's the game I'm going to solve using JMP, in its original form.
[Find the value of a ball of each color, knowing that the total of the balls on a line is always equal to 12]
There are at least three ways to solve this-- probably more, if I thought about these things longer than it took me to eat a Happy Meal™ at Chez McDo's.
Method 1: Brute Force
A very brute-force approach is to loop through all the possible colors (red = x, brown = y, black = z. blue = w) recognizing that they can't be less than zero nor more than 12. Here's a JMP script that does that : Four For loops that cycle each value from 0 to 12 in steps of 0.5. When it hits a result, it writes the result to the log.
For( x = 1, x <= 12, x += 0.5,
For( y = 1, y <= 12, y += 0.5,
For( z = 1, z <= 12, z += 0.5,
For( w = 1, w <= 12, w += 0.5,
If( 2 * z + 2 * w == 12,
If( z + 2 * y + w == 12,
If( 3 * y + 2 * x == 12,
If( z + y + 4 * w == 12,
If( z + w + 4 * x == 12,
Show( x, y, z, w );
The results? red = 1.5, brown = 3, black = 5. blue = 1
Method 2: Least-Squares
The next way is to recognize this as a least-squares problem. The value attached to the balls are the coefficients of a linear model, with the balls themselves serving as the data. So, I can make a JMP Data Table that holds the five rows and information on the four colored balls. To wit:
And using JMP's Fit Model window, I can get least-squares estimates on the balls. I'm using a no-intercept model because I know that the linear model should go through the origin.
Like that ("Bam!," I say to myself), I get the results and the answer to the puzzle.
Method 3. Using Math
If you took Algebra II in the past 40 years, you studied these things called matrices. Turns out they're actually useful. And if you don't recognize the puzzle in its least-squares sense, there's always this mathematical way of looking at it. Don't tell anyone, but they're actually the same approach: The math you see below is what's going on behind the scenes in JMP.
If you express the puzzle set-up using matrices (five rows representing the five rows of the puzzle), you can have the table itself represented like this (call it A).
A = [0 0 2 2
0 2 1 1
2 3 0 0
0 1 1 4
4 0 1 1]
and the fact that these five conditions all sum to 12, represented as
C = [12
with a final matrix b representing the unknowns : the value of the balls.
b = [x
To solve this, we simply have to start with
Ab = C
and get b alone on the left side of the equation. Typically, we'd do the simple thing of multiplying both sides by A-1, like this:
A-1Ab = A-1C
But don't you know there's a problem. Since the puzzle has four variables and five rows, its matrix representation isn't square. So we can't just use an ordinary inverse. We can multiply A by its transpose to get a square matrix, although this still isn't invertible. Luckily, JMP has the Moore-Penrose Generalized Inverse function (which sounds better in italics, don't you think?). Using it, I can write a simple JMP script to assign the matrices and solve the problem: