Enigmatic Code

Programming Enigma Puzzles

Enigma 1649: Draw conclusions

From New Scientist #2815, 4th June 2011 [link]

Joe was asked to arrange a lottery for a local charity. He made a pack of cards with one of just two numbers on each card. One could select to draw any number of cards from the pack. Prizes were awarded according to the total of the numbers on the cards drawn.

Checking numbers which could be allocated prizes, Joe found that below 60 some totals were not achievable, some could be achieved in one way and some in more ways. The total of 59 could only be achieved in one way, but all higher totals could be achieved in more than one way, that is, if Joe had provided enough cards.

What were the two numbers on the cards?



One response to “Enigma 1649: Draw conclusions

  1. Jim Randell 5 December 2011 at 5:33 pm

    The following Python code runs in 72ms.

    from enigma import irange
    def check(a, b):
      # check combinations below 120
      N = 120
      c = [0] * N
      for n in irange(0, int(N / a)):
        for m in irange(0, int((N - a*n) / b)):
          s = a * n + b * m
          if not(s < N): continue
          c[s] += 1
      if not(c[59] == 1): return
      if c[:60].count(0) < 2: return
      if len([x for x in c[:60] if x > 1]) < 2: return
      if len([x for x in c[60:] if x > 1]) < N - 60: return
      print(a, b, c[:60], c[60:])
    # OK, let's assume a < b
    for b in irange(3, 59):
      for a in irange(2, b - 1):
        check(a, b)

    Solution: The two numbers on the cards are 4 and 9.

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: