StackAdapt experiments may model a fixed number of successful outcomes across a small sequence of independent trials. Given n coin positions, exactly k of which are heads, some observed outcomes, and an unobserved target position, compute the conditional probability that the target position is heads.
Assume every sequence containing exactly k heads is equally likely. The observed outcomes are guaranteed to be mutually consistent, and the target position is not observed.
For the original four-coin form, if coin 3 is known to be heads and exactly 2 of the 4 coins are heads, the probability that coin 4 is heads is 1/3. Without the exact-heads condition, fair independent coins would give probability 1/2.
Implement probability_target_head(n, k, observed, target). n and k are integers. observed is a list of [zero_based_index, is_heads] pairs, where is_heads is a Boolean. target is an unobserved zero-based index. Return a floating-point probability between 0.0 and 1.0.
def probability_target_head(n, k, observed, target):