Find how often peeking rolls back a healthy canary

Agent buildHard40 min

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 -line by the end of the last pair, there is no rollback.

Examples

false_rollback(pairs: int, line: int) -> float
Example 1
Inputfalse_rollback(1, 1)
Output0.5
Example 2
Inputfalse_rollback(4, 2)
Output0.375
Example 3
Inputfalse_rollback(3, 5)
Output0