Friday, September 21, 2007

Enigma 1461

Here is how Mathematica can be used to solve New Scientist Enigma number 1461 in the 22 September 2007 issue. The solution is optimised for clarity rather than brevity.

Generate a list of all the 24-hour clock squares.
squares = Select[Flatten[Outer[100#1+#2&, Range[0,23], Range[0,59]]], IntegerQ[Sqrt[#]]&]
{0, 1, 4, 9, 16, 25, 36, 49, 100, 121, 144, 225, 256, 324, 400, 441, 529, 625, 729, 841, 900, 1024, 1156, 1225, 1444, 1521, 1600, 1849, 1936, 2025, 2116, 2209, 2304}

Generate all 3-tuples from the list of squares. The convention is that each 3-tuple corresponds to {Tom, Dick, Harry}.
(tuples = Tuples[squares, 3]) // Length
35937

Week 1: filter the list of 3-tuples so that T < D < H and also H = T + D.
(triples1a = Select[tuples, #[[1]]<#[[2]]<#[[3]]&]) // Length
(triples1b = Select[triples1a, #[[3]]==#[[1]]+#[[2]]&]) // Length
5456
5

Use the cyclical relationship between the weeks to obtain the corresponding results for weeks 2 and 3.
triples2b=Map[RotateLeft, triples1b];
triples3b=Map[RotateRight, triples1b];

Extract the case where Harry's square is the same for all weeks, keeping only the value of Harry's square.
harrysquare = Intersection[triples1b, triples2b, triples3b, SameTest->(#1[[3]]==#2[[3]]&)][[1,3]]
400

Extract the 3-tuple of squares {Tom, Dick, Harry} for each week that contain the above value of Harry's square.
tdhsquares = Map[Cases[#, {_,_,harrysquare}][[1]]&, {triples1b, triples2b, triples3b}]
{{144,256,400}, {441,841,400}, {625,225,400}}

Extract Tom's squares.
Transpose[tdhsquares][[1]]
{144, 441, 625}

5 comments:

robert tough said...

It is good to see that you're still rocking dude. Ars gratia artis, and fuck the lot of them

Stephen Luttrell said...

Adhuc nihil fere vidisti.

RT said...

I have to admit that that is not in my Latin phrase book (ars gratia artis was, however, a prog rock track by Keith Emerson's nice back in the day . 10 cc - an exceptional ejaculate - had it as art 4 art's sake, money 4 god's sake) Do construe.

Stephen Luttrell said...

As yet hardly anything you have seen.

My apologies to Al Jolson.

rt said...

I'm both educated and glad to hear it