Skip to content

Instantly share code, notes, and snippets.

@neel04
Created October 26, 2023 14:38
Show Gist options
  • Save neel04/a30b3bb2469a8a5c94f29a43f99a8116 to your computer and use it in GitHub Desktop.
Save neel04/a30b3bb2469a8a5c94f29a43f99a8116 to your computer and use it in GitHub Desktop.
(Possible) solution to the puzzle

To be completely honest, I think the puzzle is badly phrased (and the edits don't really help)

Assumptions: We have a queue of n orders. The machine chooses $3$ random orders from n in an unbiased fashion.

"...Forgets about any orders that were skipped"

Is either redundant, or it implies that the machine chooses $3$ random orders, but in the next round chooses from $n-3$ orders.

That assumes we're taking a batch of $3$ orders, as restaurants usually do. So it's $n \choose 3$. Or we could be taking 1 order from the top 3 orders, so $3 \choose 1$.

But,

"..Instead of processing each order sequentially.."

Implying that the machine will not work sequentially. So it consumes by batches of $3$?

Therefore, new assumption:

  • we have n orders.
  • The machine usually goes sequentially (no batching) and now, it simply randomly chooses an order from the top-3, recursively repeating the process.
  • Whenever the machine "processes" an order, it'd be removed from the queue.

We ignore the groups initially, because they make little sense even after the edits: if there are always 3 unprocessed orders, and we're the first one in the restaurant, why the first group then already has arrived - unless there are some ghosts in the restaurant who live there just to pad up to three orders in the off-chance the machine starts worshipping the trinity.

So let's say the queue is like this: 1, 2, [3], 4, 5, .... Our order is the square bracketed one.

Because the machine chooses top-3, as a rolling window, and it "ignores orders that were skipped" therefore, if it chooses 2 then the queue is: 1, [3], 4, 5, ...

Thus, can maximize our chances by maximizing the time we spent in the top-3 window.

Because on the 1/9 chance 1 or 2 are selected, we simply become the first order: [3], 4, 5, ...

So, as long as we start in at any position in the top-3, we always remain in the $3 \choose 1$ window and thus maximize chances of our order being processed.

I'm aware this is not a real "solution" per se - its literally the obvious solution, but that's with what I think is the closest interpretation of the question.


PS: was planning to write a solution for every combination of interpretation of the question, but then half-way through realized that nobody had the time to read 5 pages plus I didn't want to be that guy:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment