A party is being held at a local mansion. The host is very rich and his success is because of one thing — his famous recipe for Spaghetti!
The only guests that may attend are people who correctly reply to the guard at the door.
Here's where you come in. You and a friend are trying to steal this recipe. You sneak by and listen to the passwords.
However, when the first guest arrives, you are dismayed to find that the guard does not ask them a question, but merely motions for them to stand by the gate. When the second guest arrives, the guard motions to them too, and they line up behind the first guest. This goes on until at last there are 19 guests lined up.
The guard looks at his watch and says, "Well, I think everyone is here, but we will wait a couple of minutes just in case there are any stragglers." At this you and your friend realize that this is your last chance so you quickly come out and line up at the end.
"As you know," says the guard. "There have been many attempts made to steal our host's secret recipe, and at every party somebody has managed to learn the password scheme and sneak in when they shouldn't." The guards eyes each of the guests one by one, as if to divine any unauthorized guests presently in attendance, but when his eyes meet yours you stare right back at him dumbly.
"So our host has gone back and picked a variant on one of his earlier schemes that his thinks perhaps nobody outside our group quite caught on to and mixed it up a bit. And just to wise up a little, as you know, you are all standing here together before I will start asking the questions, so as to not leak any information. Is everybody ready for me to give out the number?"
You and your friend see everyone else nodding, so you nod too, fearful of what is going to come next.
The guard pulls out his clipboard and then counts all the potential guests. "I see 21 people," he begins, and scanning down his clipboard he quickly calls out, "The challenge is thirteen thousand eight hundred and thirty two. We will start at the head of the line and work backwards."
"5" says the first guest after a few moments, and he is let in. "12" says the second guest. The guard nods and lets him by. "16". "Yes." "17" "Sure". "14" says the fifth guest. "Your answer is baseless!" exclaims the guard and a out of nowhere a large gorilla zip-lines across the group and snatches up the fifth guest and carries him off. "The correct answer was 40!" the guard says loudly, then smiles at the sixth guest. "No reason for you to have to figure out two answers, eh?" The sixth guest nods, then says "65". "Correct."
The remaining guests in front of you all answer correctly. Starting with the 7th guest, the answers are: 72,58,38,31,32,37,44,29,56,27,52,11, and 22.
Before it gets to your friend, who is in front of you, he turns and whispers to you, "Well it's pretty obvious this isn't just a random sequence, isn't it? If there had been one more person, he would have had the same number as me!" but then it is his turn and he has to turn and quickly answer: "35".
The guard eyes him over for a minute, then replies, "Correct."
Now it is your turn! What number do you tell the guard?
If there were only 4 guests, the guard would have been in a pickle! He would have had to challenge with "14" and the correct responses from each guest in order would have been "3", "4", "5" and "6". Fortunately the host knew that at least 6 people would show up ("27" -> "4", "6", "7", "9", 3", "1").
The guard must base his challenge on the number of guests that show up at the door. Your friend figures out why before he gives his response.