A300576 Number of nights required in the worst case to find the princess in a castle with n rooms arranged in a line (Castle and princess puzzle).
1, 2, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122
Offset: 1
Examples
For n = 1, there is only one room to search, so a(1) = 1. For n = 2, the prince searches room 1 on the first night. If the princess is not there that means she was in room 2. If the prince searches room 1 again then he is guaranteed to see the princess as she has to move from room 2 to room 1 (she cannot stay in the same room). So a(2) = 2. For n = 3, the prince searches room 2 on the first night. If the princess is not there that means she was either in room 1 or 3. On the second night she must go to room 2 and this is where the prince will find her. So a(3) = 2. For n = 4, a solution that guarantees to find the princess in a(4)=4 nights is to search rooms (2,3,3,2). For n = 5, a solution that guarantees to find the princess in a(5)=6 nights is to search rooms (2,3,4,4,3,2). In the general case for n >= 3, a solution guaranteeing success in the minimum number of nights is to search rooms (2,3,...,n-1,n-1,...,3,2), so a(n) = 2*n - 4.
Links
- Christian Perfect, Solving the princess on a graph puzzle.
- Puzzling Stack Exchange, Why does this solution guarantee that the prince knocks on the right door to find the princess?.
- standupmaths, Youtube, The Castle and the Princess Puzzle.
- Index entries for linear recurrences with constant coefficients, signature (2,-1).
Crossrefs
Programs
-
Mathematica
CoefficientList[ Series[(2x^3 - x^2 + 1)/(x - 1)^2, {x, 0, 62}], x] (* Robert G. Wilson v, Mar 12 2018 *) Join[{1,2},Range[2,200,2]] (* Harvey P. Dale, Jan 25 2019 *)
Formula
For n >= 3, a(n) = 2*n - 4.
From Chai Wah Wu, Apr 14 2024: (Start)
a(n) = 2*a(n-1) - a(n-2) for n > 4.
G.f.: x*(2*x^3 - x^2 + 1)/(x - 1)^2. (End)
E.g.f.: 4 + 2*exp(x)*(x - 2) + 3*x + x^2. - Stefano Spezia, Aug 15 2025
Comments