Enigmatic Code

Programming Enigma Puzzles

Enigma 1015: Money-spinner

From New Scientist #2171, 30th January 1999 [link]

In my local pub there is an electronic “slot machine” which offers a choice of various games. In one of them, called Primetime, after inserting your pound coin the 9 digits 1-9 appear in random order around a circle. Then an arrow spins and stops between two of the digits. You win the jackpot if the two-digit number formed clockwise by the two digits on either side of the arrow has a two-figure prime factor. So, if the digits and arrow ended up as above, you would win the jackpot because 23 is a factor of 92.

However, with the digits in the same position but with the arrow between 8 and 1 you wound not win.

I recently played the game. The digits appeared and the arrow started to spin. But I realised to my annoyance that, no matter where the arrow stopped, I could not with the jackpot.

Starting with 1, what is the clockwise order of the digits?


2 responses to “Enigma 1015: Money-spinner

  1. Jim Randell 13 April 2019 at 12:58 pm

    This Python 3 program finds the answer recursively in 97ms.

    Run: [ @repl.it ]

    from itertools import permutations
    from collections import defaultdict
    from enigma import irange, prime_factor, printf
    # find 2-digit numbers that do not have a 2-digit prime factor
    # store them as a map of: <tens digit> -> <possible unit digits>
    d = defaultdict(list)
    for (a, b) in permutations(irange(1, 9), 2):
      if any(p > 10 for (p, e) in prime_factor(10 * a + b)): continue
    # add k more digits to the sequence s
    def solve(s, k):
      # are we done?
      if k == 0:
        # check the the last and first digit
        if s[0] in d[s[-1]]:
          yield s
        # consider the next digit
        for x in d[s[-1]]:
          # we can't have already used it
          if x in s: continue
          # solve for the rest
          yield from solve(s + [x], k - 1)
    # start with digit 1, and add 8 more digits
    for s in solve([1], 8):
      # output the sequence

    Solution: The digits are: 1, 6, 3, 2, 7, 5, 4, 9, 8.

    Giving the 2-digit numbers: 16, 63, 32, 27, 75, 54, 49, 98, 81.

  2. Hugh Casement 13 April 2019 at 2:09 pm

    That is the only order out of 8! = 40320 in which no prime factor greater than 7 occurs.

    Factor 11 is not possible, because there can be no double digits.
    I think I’m right in saying that in 72 games one could expect to win (on average) with factor 13 seven times, 17 and 19 five times each, 23 four times, 29 and 31 three times each, 37, 41, 43, and 47 twice each, and each higher prime up to 97 once. That is an overall probability 5/8 = 0.625 of winning.

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: