Monday, October 7, 2019

The cook math puzzle

"How many guests are there?" said the official.
"I don't know.", said the cook, "but every 2 used a dish of rice, every 3 used a dish of broth, and every 4 used a dish of meat between them".  There were 65 dishes in all.  How many guests were there?



Let us investigate some earlier ones.

The first three guests used a dish of rice and a dish of broth; that would be two dishes.
The fourth used used a dish of rice and a dish of meat; that would be two more dishes.
The sixth used a dish of rice, and a dish of broth; that would be two more dishes.
The eight used a dish of rice, and a dish of meat; that would be two more dishes.
The ninth used a dish of broth; that would be one more dish.
The tenth used a dish of rice; that would be one more dish.
The twelfth used a dish of rice, a dish of broth, and a dish of meat; that would be three more dishes.

I think we can in fact find an iterative summation algorithm here:

  • dishCount = 0
  • numGuests = 1
  • while (dishCount < 65):
    • if (numGuests is a multiple of 2):
      • dishCount += 1
      • Immediately exit loop if dishCount is at or exceeds 65
    • if (numGuests is a multiple of 3):
      • dishCount += 1
      • Immediately exit loop if dishCount is at or exceeds 65
    • if (numGuests is a multiple of 4):
      • dishCount += 1
      • Immediately exit loop if dishCount is at or exceeds 65
  • print("The number of guests is: " + str(numGuests))

Asking if a given integer is a multiple of n is equivalent to asking if the said integer does not produce a remainder when divided by n. 


Thus, we arrive at the following Python code:

dishCount = 0  
numGuests = 1

while (dishCount < 65):
    print("Current number of guests: " + str(numGuests) + ", current dishes served: " + str(dishCount))
   
    if (numGuests%2 == 0):
        dishCount += 1
        print("Current number of guests: " + str(numGuests) + ", dish of rice served.")
        if (dishCount >= 65):
            continue

    if (numGuests%3 == 0):
        dishCount += 1
        print("Current number of guests: " + str(numGuests) + ", dish of broth served.")
        if (dishCount >= 65):
            continue

    if (numGuests%4 == 0):
        dishCount += 1
        print("Current number of guests: " + str(numGuests) + ", dish of meat served.")
        if (dishCount >= 65):
            continue   

    numGuests += 1


print("The number of guests is: " + str(numGuests))

The program prints 60:

Current number of guests: 1, current dishes served: 0                                                                          
Current number of guests: 2, current dishes served: 0                                                                          
Current number of guests: 2, dish of rice served.                                                                              
Current number of guests: 3, current dishes served: 1                                                                          
Current number of guests: 3, dish of broth served.                                                                             
Current number of guests: 4, current dishes served: 2                                                                          
Current number of guests: 4, dish of rice served.                                                                              
Current number of guests: 4, dish of meat served.                                                                              
Current number of guests: 5, current dishes served: 4                                                                          
Current number of guests: 6, current dishes served: 4                                                                          
Current number of guests: 6, dish of rice served.                                                                              
Current number of guests: 6, dish of broth served.                                                                             
Current number of guests: 7, current dishes served: 6                                                                          
Current number of guests: 8, current dishes served: 6                                                                          
Current number of guests: 8, dish of rice served.                                                                              
Current number of guests: 8, dish of meat served.                                                                              
Current number of guests: 9, current dishes served: 8                                                                          
Current number of guests: 9, dish of broth served.                                                                             
Current number of guests: 10, current dishes served: 9                                                                         
Current number of guests: 10, dish of rice served.                                                                             
Current number of guests: 11, current dishes served: 10                                                                        
Current number of guests: 12, current dishes served: 10                                                                        
Current number of guests: 12, dish of rice served.                                                                             
Current number of guests: 12, dish of broth served.                                                                            
Current number of guests: 12, dish of meat served.                                                                             
Current number of guests: 13, current dishes served: 13                                                                        
Current number of guests: 14, current dishes served: 13                                                                        
Current number of guests: 14, dish of rice served.                                                                             
Current number of guests: 15, current dishes served: 14                                                                        
Current number of guests: 15, dish of broth served.                                                                            
Current number of guests: 16, current dishes served: 15                                                                        
Current number of guests: 16, dish of rice served.                                                                             
Current number of guests: 16, dish of meat served.                                                                             
Current number of guests: 17, current dishes served: 17                                                                        
Current number of guests: 18, current dishes served: 17                                                                        
Current number of guests: 18, dish of rice served.                                                                             
Current number of guests: 18, dish of broth served.                   
Current number of guests: 19, current dishes served: 19                                                                        
Current number of guests: 20, current dishes served: 19                                                                        
Current number of guests: 20, dish of rice served.                                                                             
Current number of guests: 20, dish of meat served.                                                                             
Current number of guests: 21, current dishes served: 21                                                                        
Current number of guests: 21, dish of broth served.                                                                            
Current number of guests: 22, current dishes served: 22                                                                        
Current number of guests: 22, dish of rice served.                                                                             
Current number of guests: 23, current dishes served: 23                                                                        
Current number of guests: 24, current dishes served: 23                                                                        
Current number of guests: 24, dish of rice served.                                                                             
Current number of guests: 24, dish of broth served.                                                                            
Current number of guests: 24, dish of meat served.                                                                             
Current number of guests: 25, current dishes served: 26                                                                        
Current number of guests: 26, current dishes served: 26                                                                        
Current number of guests: 26, dish of rice served.                                                                             
Current number of guests: 27, current dishes served: 27                                                                        
Current number of guests: 27, dish of broth served.                                                                            
Current number of guests: 28, current dishes served: 28                                                                        
Current number of guests: 28, dish of rice served.                                                                             
Current number of guests: 28, dish of meat served.                                                                             
Current number of guests: 29, current dishes served: 30                                                                        
Current number of guests: 30, current dishes served: 30                                                                        
Current number of guests: 30, dish of rice served.                                                                             
Current number of guests: 30, dish of broth served.                                                                            
Current number of guests: 31, current dishes served: 32                                                                        
Current number of guests: 32, current dishes served: 32                                                                        
Current number of guests: 32, dish of rice served.                                                                             
Current number of guests: 32, dish of meat served.                                                                             
Current number of guests: 33, current dishes served: 34                                                                        
Current number of guests: 33, dish of broth served.
Current number of guests: 34, dish of rice served.                                                                             
Current number of guests: 35, current dishes served: 36                                                                        
Current number of guests: 36, current dishes served: 36                                                                        
Current number of guests: 36, dish of rice served.                                                                             
Current number of guests: 36, dish of broth served.                                                                            
Current number of guests: 36, dish of meat served.                                                                             
Current number of guests: 37, current dishes served: 39                                                                        
Current number of guests: 38, current dishes served: 39                                                                        
Current number of guests: 38, dish of rice served.                                                                             
Current number of guests: 39, current dishes served: 40                                                                        
Current number of guests: 39, dish of broth served.                                                                            
Current number of guests: 40, current dishes served: 41                                                                        
Current number of guests: 40, dish of rice served.                                                                             
Current number of guests: 40, dish of meat served.                                                                             
Current number of guests: 41, current dishes served: 43                                                                        
Current number of guests: 42, current dishes served: 43                                                                        
Current number of guests: 42, dish of rice served.                                                                             
Current number of guests: 42, dish of broth served.                                                                            
Current number of guests: 43, current dishes served: 45                                                                        
Current number of guests: 44, current dishes served: 45                                                                        
Current number of guests: 44, dish of rice served.                                                                             
Current number of guests: 44, dish of meat served.                                                                             
Current number of guests: 45, current dishes served: 47                                                                        
Current number of guests: 45, dish of broth served.                                                                            
Current number of guests: 46, current dishes served: 48                                                                        
Current number of guests: 46, dish of rice served.                                                                             
Current number of guests: 47, current dishes served: 49                                                                        
Current number of guests: 48, current dishes served: 49                                                                        
Current number of guests: 48, dish of rice served.                                                                             
Current number of guests: 48, dish of broth served.                                                                            
Current number of guests: 48, dish of meat served.                                                                             
Current number of guests: 49, current dishes served: 52                                                                        
Current number of guests: 50, current dishes served: 52                                                                        
Current number of guests: 50, dish of rice served.                                                                             
Current number of guests: 51, current dishes served: 53                      
Current number of guests: 51, dish of broth served.                                                                            
Current number of guests: 52, current dishes served: 54                                                                        
Current number of guests: 52, dish of rice served.                                                                             
Current number of guests: 52, dish of meat served.                                                                             
Current number of guests: 53, current dishes served: 56                                                                        
Current number of guests: 54, current dishes served: 56                                                                        
Current number of guests: 54, dish of rice served.                                                                             
Current number of guests: 54, dish of broth served.                                                                            
Current number of guests: 55, current dishes served: 58                                                                        
Current number of guests: 56, current dishes served: 58                                                                        
Current number of guests: 56, dish of rice served.                                                                             
Current number of guests: 56, dish of meat served.                                                                             
Current number of guests: 57, current dishes served: 60                                                                        
Current number of guests: 57, dish of broth served.                                                                            
Current number of guests: 58, current dishes served: 61                                                                        
Current number of guests: 58, dish of rice served.                                                                             
Current number of guests: 59, current dishes served: 62                                                                        
Current number of guests: 60, current dishes served: 62                                                                        
Current number of guests: 60, dish of rice served.                                                                             
Current number of guests: 60, dish of broth served.                                                                            
Current number of guests: 60, dish of meat served.                                                                             
The number of guests is: 60                                                  

      
I think I can whip out a formula at this point:

d/2 + d/3 + d/4 = 65
6d + 4d + 3d = 780
13d = 780
d = 60

No comments:

Post a Comment