Enigmatic Code

Programming Enigma Puzzles

Enigma 1268: Scoop!

From New Scientist #2424, 6th December 2003 [link]

For a summer job I work in an ice-cream parlour. We sell six-scoop “specials” in which customers can choose one scoop each of six different flavours from our extensive range.

One day, a coach party consisting of a prime number of people came in and they each ordered a six-scoop special. I noticed that if you looked at any pair of flavours from our extensive range, then that pair was in precisely one of the coach party’s specials.

How many flavours are there in our extensive range, and how many of the coach party included vanilla (the most popular of our flavours) in their specials?

[enigma1268]

Advertisements

2 responses to “Enigma 1268: Scoop!

  1. Jim Randell 25 December 2014 at 8:44 am

    A bit of analysis (presented in the comments) gives a straightforward program to solve this puzzle.

    This Python program runs in 34ms.

    from itertools import count
    from enigma import C, is_prime, printf
    
    # each special has 6 different scoops
    # so has C(6,2) flavour pairs in it
    n = C(6, 2)
    
    # and these pairs cannot occur in any other special
    
    # consider just one flavour, in each special it is paired with 5 other
    # flavours, and these cannot be repeated, so if it appears in k
    # specials it is paired with 5k other flavours, but it must be paired
    # with every other flavour, so the total number of flavours must be
    # 5k + 1.
    
    # suppose there are f flavours (f = 5k + 1)
    for k in count(1):
      f = 5 * k + 1
    
      # the total number of flavour pairs is C(f, 2)
      t = C(f, 2)
    
      # and these are divided amongst the specials ordered
      (p, r) = divmod(t, n)
      if r > 0: continue
    
      # and that number should be prime
      if not is_prime(p): continue
    
      printf("k={k} f={f} p={p}")
      break
    

    Solution: There are 31 flavours. 6 of the specials ordered included vanilla.

    There are 31 people in the coach party. Each (and every) flavour is included in exactly 6 of the specials ordered by the coach party.

    • Jim Randell 26 December 2014 at 9:00 am

      Given the analysis above we see that the number of people is:

      p = k(5k + 1)/6

      Which has integer solutions when k = 3n and k = 3n + 1.

      [Case 1] For k = 3n:

      p = n(15n + 1)/2

      [Case 1a] When n is even, n = 2m

      p = m(30m + 1)

      which will be composite when m > 1, and when m = 1 (k = 6) gives p = 31, which is prime and thus gives rise to a solution.

      [Case 1b] When n is odd, n = 2m+1

      p = (2m + 1)(15m + 8)

      which is obviously composite for m > 0, and when m = 0 gives p = 8, which is also composite. So gives no further solutions.

      [Case 2] For k = 3n + 1:

      p = (3n + 1)(5n + 2)/2

      [Case 2a] When n is even, n = 2m

      p = (6m + 1)(5m + 1)

      which is composite for m > 0, and gives p = 1 (a non-prime) when m = 0. So gives no further solutions.

      [Case 2b] When n is odd, n = 2m + 1:

      p = (3m + 2)(10m + 7)

      which is composite for m > 0, and gives p = 14 (composite) for m = 0. So gives no further solutions.

      Hence there is a single solution when k = 6 of p = 31.

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: