Find how often peeking rolls back a healthy canary
Your task
A canary puts a new version of your agent on a small slice of traffic. Your controller compares it with the current version on paired tasks, and it looks at the running score after every pair.
Write false_rollback(pairs, line) that returns the chance that a version no better and no worse than the current one gets rolled back.
Input and output:
pairs: how many pairs the canary runs for, a whole number from 1 to 5,000,000.line: how far behind sets off the rollback, a whole number from 1 to 5,000,000.- Return a float. The tests accept any value within 0.000001 of the exact one.
Rules:
- The score starts at 0. Each pair moves it up 1 when the new version wins and down 1 when it loses, each with a chance of one half, whatever the other pairs did.
- The rollback happens the first time the score reaches
-line, and no more pairs run after it. - If the score has not reached
-lineby the end of the last pair, there is no rollback.
Examples
false_rollback(pairs: int, line: int) -> floatExample 1
Input
false_rollback(1, 1)Output
0.5Example 2
Input
false_rollback(4, 2)Output
0.375Example 3
Input
false_rollback(3, 5)Output
0