4 kyu

Bribe the Guards of the Crown Jewels

160 of 234ecolban
Description
Loading description...
Dynamic Programming
Algorithms
  • Please sign in or sign up to leave a comment.
  • RomeroDiver Avatar

    I don't understand the underlying maths: e.g. if we start at 7, and the jewels are behind doors number 10, we haveto pay 7 + 8 + 9 + 10 = 34, however the description says it is 26. Where is 26 coming from?

  • saudiGuy Avatar

    This comment has been hidden.

  • saudiGuy Avatar
  • dfhwze Avatar

    This comment has been hidden.

  • iz-Moff Avatar

    This one had me stuck for a while. I think the description of the problem is somewhat confusing. It kinda makes it sound like you are expected to do the binary search, just starting from the optimal position, rather than from the middle of the list. This part: You are better off if you first go to room 7. In the worst case the guard will direct you to the right(i.e., higher numbered rooms) and then you go to room 9. should probably emphasize that you're not just picking room 9 because it happens to be in the middle of 8,9,10, but actually choosing the most "cost efficient" room at each step. And it's only made more confusing by the fact that a "nudged" binary search will solve the simple cases, which made me go crazy thinking that i must be on the right track and only failing harder cases because of some dumb mistake, like not splitting the list properly or something.

    But apart from that, i think it is an interesting problem, searching for the worst outcome of making the best choice rather than the best choice itself.

  • Sturmpuls Avatar

    This comment has been hidden.

  • cwilker7 Avatar

    This comment has been hidden.

  • josephmlullo Avatar

    This doesn't make any sense to me. I think you're asking to find the path to the door with the minumum cost given some worst case scenario, but what is your definition of worst case scenario? It seems completely arbitrary.

    It's not that the final door has the highest cost (per your explanation for ([5, 1, 2, 4, 3]), 8)). It's not that the path to the door is the longest (per your explanation for [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 26). It's not choosing the first door that results in the highest possible costs and finding the min cost among the resulting possible paths (per your explanation for ([1, 2, 3, 4, 5]), 9)).

    I don't know what else it could be. The test cases and explanations seem contradictory.

  • ziereis Avatar

    I just read the description like 5 times and still don't get your idea of a worst case scenario. Obviously you need the sum of all the bribes in the worst case scenario which is that you guess the right door after attempting all the others first. But that doesn't involve any coding, so I'm back at square one totally clueless about what I'm supposed to do.

  • subrahmanya_ug Avatar

    This comment has been hidden.

  • tommur Avatar

    This comment has been hidden.

  • JohanWiltink Avatar
  • Voile Avatar

    Approved ;-)

  • Voile Avatar

    Python 3 should be enabled because Python 2 is going to be deprecated soon.

  • daddepledge Avatar

    A really good Kata, thanks. I used pen, paper and thinking. Top notch.

  • emptyopen Avatar

    Maybe I'm not understanding the setup, but it seems to me like the answers are wrong?

    test.assert_equals(least_bribes([1, 2, 3, 4, 5]), 9) If I pay $3 for the middle door and $4 for the fourth door, that is the worst cost for knowing which door the treasure is behind. 3+4=7 < 9

    test.assert_equals(least_bribes([5, 1, 2, 4, 3]), 8) Similarly, pay $2, $3: 5 < 8

    test.assert_equals(least_bribes([3, 2, 5, 4, 1]), 10) Again, worst case is $5, $4 = 9 which is less than 10

  • ChristianECooper Avatar

    This comment has been hidden.