pull down to refresh

You're on the right track, but the solution is not quite accurate yet.
For example, if N=3, your solution says take 3. But that's rude because you take the last dumpling.
Another example, if N=5, your solution says take 1. But if N=5, you can take 3, then the next person will take 1, leaving the next person with the last dumpling. This maximizes your dumplings without being rude.
Ah yes, how about this:
optimal_move = if N ≤ 2: invalid if N ≤ 4: N-1 if N mod 4 ∈ {1,3}: 2 if N mod 4 ∈ {0,2}: 3
reply