Enigmatic Code

Programming Enigma Puzzles

Puzzle #86: Yam tomorrow

From New Scientist #3309, 21st November 2020 [link] [link]

Three shipwrecked sailors discover a crate of yams on the beach. The crate is labelled “100 Yams”, but they notice it has been prised open and some of the yams have been pinched, possibly by the monkey they spot nearby. In the night, one of the sailors, Abel, wakes and decides he will take one-third of the yams, but he can only do so in whole yams if he first gives one to the monkey. Later, Babel has the same idea, but again to take one-third in whole yams, he has to first give the monkey a yam; and later still, the same thing happens with Cabel. In the morning, the three sailors, who have all hidden their secret stashes, share out what yams remain equally among them, and this time around the poor monkey receives nothing.

How many yams did they each end up with in total?

[puzzle#86]

5 responses to “Puzzle #86: Yam tomorrow

  1. Jim Randell 21 November 2020 at 8:39 am

    This is a “monkey and coconut” problem. See: Enigma 258.

    This Python program considers possible numbers of yams per sailor in the final distribution, and the other amounts can be derived from this.

    It runs in 54ms.

    Run: [ @repl.it ]

    from enigma import irange, printf
    
    # suppose the final number of yams per sailor is y
    for y in irange(1, 31):
      # the final pile is 3y = 2c
      (c, r) = divmod(3 * y, 2)
      if c > 32: break
      if r != 0: continue
      # the pile before C took his = 3c + 1 = 2b
      (b, r) = divmod(3 * c + 1, 2)
      if b > 32: break
      if r != 0: continue
      # the pile before B took his = 3b + 1 = 2a
      (a, r) = divmod(3 * b + 1, 2)
      if a > 32: break
      if r != 0: continue
      # initially the pile was n = 3a + 1
      n = 3 * a + 1
      # output solution
      (A, B, C, M) = (a + y, b + y, c + y, (100 - n) + 3)
      printf("A={A} B={B} C={C} M={M} [n={n}; a={a} b={b} c={c} y={y}]")
    

    Solution: In total Abel got 10 yams; Babel got 7 yams; Cabel got 5 yams.

    And the monkey got 78 yams.

    Initially there were 25 yams in the crate. So the monkey had already taken 75.

    A gave 1 to the monkey, and took 8, leaving 16.

    B gave 1 to the monkey, and took 5, leaving 10.

    C gave 1 to the monkey, and took 3, leaving 6.

    The remaining 6 yams were divided up giving A, B, C each 2 yams.

    • Tina 26 November 2020 at 4:35 am

      How do I determine that the monkey already pinched 75 of the rams ?

      • Jim Randell 26 November 2020 at 8:30 am

        @Tina: The only possible starting number of yams less than 100 in the crate that lets the procedure work is 25. So 75 of the original 100 yams are missing before the sailors start dividing them up. They have presumably been taken by the monkey.

        The next smallest possible starting number would be 106 (corresponding to 30 yams in the final pile divided between A, B, and C), but there were only 100 yams in the crate to start with, so this (and any larger numbers) is not possible.

  2. Arie Rozengart 3 December 2020 at 9:01 am

    The New-Scientist puzzles can be solved with basic algebra and logic, without programming code that finds the solution. I solved Puzzle #86 twice. Once starting with the 3a+1 as the initial number of yams in the box. Second time starting with 2a as the number of yams left over in the box in the end.
    It took me less time to get the right answers than it would take me to write a code, and I am an experienced programmer.

    • Jim Randell 3 December 2020 at 10:35 am

      Certainly puzzles in the current Puzzle # series tend to be easier to solve than puzzles that were published as part of the Enigma series.

      However the main focus of this site is solving the puzzles programmatically, so I usually provide a program where possible. (Although I like to see manual solutions too).

      In this instance the program was very straightforward to write. It didn’t take me long at all.

      But here is an analytical solution (using the notation of Enigma 258):

      In general if there are M sailors, the initial number of yams would be:

      N = k.(M^M) − M + 1

      for k = 1, 2, 3, ….

      And after each of the M sailors had performed their procedure the remaining number of yams is:

      R = k.((M − 1)^M) − M + 1

      We are interested in the case when M = 3, and N is less than 100, and R is divisible by M.

      k = 1: N = 25, R = 6, (this is a viable solution)
      k = 2: N = 52, R = 14, (R is not divisible by 3)
      k = 3: N = 79, R = 22, (R is not divisible by 3)
      k = 4: N = 106, R = 30, (N is not less than 100)

      Only the k = 1 case gives a viable solution.

Leave a Comment

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