## Teaser 3119: Hidden powers

**From The Sunday Times, 3rd July 2022** [link] [link]

My grandson is studying “History since the Battle of Hastings”. I made him a game, which consisted of a row of nine cards, each with a different non-zero digit on it. Throw a standard die, note the number of spots displayed, count that number of places along the row and pause there. Throw the die again, move the corresponding number of places further along and pause again. Repeat this until you come off the end of the row, noting the digit or digits you paused on and put these together in the same order, to produce a number.

Keeping the cards in the same order I asked my grandson to try to produce a square or cube or higher power. He eventually discovered that the lowest possible such number was equal to the number of one of the years that he had been studying.

What is the order of the nine digits along the row?

[teaser3119]

## Jim Randell 5:54 pm

on1 July 2022 Permalink |It took me a little while to understand how this puzzle is supposed to work.

And despite my initial misgivings there is only one possible arrangement of digits that can lead to the situation described.

The following Python program isn’t very quick (it tries all possible arrangements of digits), but it does find the required arrangement.

The code to generate powers is adapted from

Teaser 683andEnigma 1777.It runs in 669ms.

Run:[ @replit ]Solution:The order of the digits is: 1, 9, 8, 7, 5, 2, 3, 4, 6.And the smallest (and onliest) power which can be made by rolling the die is 1936, with rolls of (1, 1, 5, 2, *).

Although the puzzle talks about the

lowestpower that can be generated, it turns out it is theonly(non-trivial) power that can be generated with the required arrangement of cards.The puzzle will continue to work in the future, until the year 4913 (= 17³) is incorporated into the history book.

LikeLike

## Jim Randell 10:13 am

on2 July 2022 Permalink |Here’s a faster (but slightly longer) program. Instead of just trying all possible arrangements of digits, it recursively constructs arrangements that

cannotgive powers less than 1066, and then finds which greater powers can be made.It runs in 174ms.

Run:[ @replit ]LikeLiked by 1 person

## Frits 11:28 pm

on1 July 2022 Permalink |Reusing my code of Teaser 683 and using Jim’s early performance enhancement (also considering number 1 as a power).

LikeLike

## Frits 9:29 am

on2 July 2022 Permalink |Python 3.9 introduced multiple arguments version of math.gcd so math.gcd() can be used instead of mult_gcd().

LikeLike

## Jim Randell 10:14 am

on2 July 2022 Permalink |Or you can use

enigma.mgcd()which will work in a wide variety of Python implementations.LikeLike

## Frits 2:50 pm

on2 July 2022 Permalink |Just as with Jim ‘s third program only calling solve() for 49 permutations.

Doing the checks for 2-digit and 3-digit powers in a general way is a bit slower.

Also storing digit positions in a dictionary to minimize index() calls is a bit slower.

LikeLike

## Frits 4:04 pm

on2 July 2022 Permalink |Without recursion.

LikeLike

## Frits 5:48 pm

on8 July 2022 Permalink |LikeLike