Enigmatic Code

Programming Enigma Puzzles

Enigma 165: Progressive games

From New Scientist #1310, 17th June 1982 [link]

Teacher gave each child 150 counters for number games.

“Make a row of piles of counters,” she said, “with each pile bigger than the previous one, and increasing by the same number each time. You needn’t use all your counters. Next, add up the total number of counters in one pile, two piles, three piles and so on. Then tell me what you notice.”

Little Alec was the first to put his hand up.

“Please miss,” he said, “all my totals are perfect squares.”

There being no other offers, Teacher tried another game.

“Now make another row, with each pile bigger than the previous one, but this time you must multiply by the same number each time to find out how big the next pile must be. Carry on until you haven’t enough counters left for another pile. Then add up the total number of counters in one pile, two piles, three piles and so on, as before. Then tell me what you notice.”

Again little Alec was the first to finish.

“Please miss,” he said, “my first two totals are the same as in the first game, and I’ve used the same number of counters altogether.”

How many was that?

[enigma165]

Advertisements

One response to “Enigma 165: Progressive games

  1. Jim Randell 30 January 2014 at 9:13 am

    This Python program runs in 34ms.

    from collections import defaultdict
    from enigma import irange, printf
    
    # squares up to 150
    squares = list(i * i for i in irange(1, 12))
    
    # generate possible sequences for game 1 (arithmetic progressions)
    def game1():
      # the sum of the counters in one pile (a) is a square
      for t1 in squares:
        yield tuple([t1])
    
        # and the sum of the first two piles (2a + d) is a square
        for t2 in squares:
          if not(t2 > 2 * t1): continue
          d = t2 - 2 * t1
          s = [t1, t1 + d]
          yield tuple(s)
    
          # find subsequent terms
          t = t2
          while True:
            s += [s[-1] + d]
            t += s[-1]
            if t not in squares: break
            yield tuple(s)
    
    # generate possible sequences for game 2 (geometric progressions)
    def game2():
      # the sum of the counters in one pile (a) is a square
      for t1 in squares:
    
        # and the sum of the first two piles (a(1 + m)) is a square
        for t2 in squares:
          (m, r) = divmod(t2, t1)
          if r > 0 or m < 2: continue
          m -= 1
          s = [t1, t1 * m]
    
          # find subsequent terms
          t = t2
          while True:
            s += [s[-1] * m]
            t += s[-1]
            if t > 150:
              yield tuple(s[:-1])
              break
    
    # record games above a minimum length by the sum of counters used and
    # the size of the first two piles
    def games(i, m):
      d = defaultdict(list)
      for s in i:
        if len(s) > m:
          d[(sum(s),) + s[:2]].append(s)
      return d
    
    # record alec's games
    g1s = games(game1(), 2)
    g2s = games(game2(), 2)
    
    # find games with the same sum and same initial values
    for (k, s2s) in g2s.items():
      for s1 in g1s[k]:
        for s2 in s2s:
          printf("total={k[0]}, game1={s1}, game2={s2}")
    

    Solution: Alec used 121 counters in each of the games.

    For the first game the sizes of the piles are: 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21. Each pile having 2 more counters than the previous pile.

    For the second game the sizes of the piles are: 1, 3, 9, 27, 81. Each pile having 3 times the number of counters of the previous pile.

    In order to arrive at an interesting and unique solution we have to suppose that Alec creates rows with more than two piles in (perhaps prompted by the teachers instructions to find the total number of counters in “the first three piles, and so on”). Without this constraint there are many degenerate solutions of two piles that satisfy the rules for either game.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: