3. Consider a uniformly shuffled collection of N objects, of which K are marked, with 1 <= K <= N. Draw objects without replacement until the first marked one appears. Let T be the number of draws, including the successful draw. I will derive E[T] and check the edge cases. Because at least one object is marked, T is always finite and lies between one and N - K + 1. The upper endpoint occurs when every unmarked object appears before any marked object. The random order is uniform, so every set of K marked positions is equally likely.

7. A tempting answer is N/K, because K/N is the probability of success on the first draw. That reciprocal would be the expectation for independent draws with replacement. Here the failure probability changes after every unmarked draw: a failure removes one unmarked object while leaving all K marked objects available. The next success becomes more likely. Therefore the geometric-distribution argument does not apply directly. I need an expression that respects sampling without replacement instead of treating each draw as an identical independent trial.

12. There are two clean ways to proceed. One uses the tail probabilities P(T > t), and the other uses symmetry among the gaps around the marked positions. I will work through the tail sum first because it makes the finite range explicit. For any positive integer-valued random variable bounded above, its expectation equals the sum of P(T > t) over all nonnegative t. To verify this, an outcome with T = r contributes one to the indicators for t = 0 through r - 1, so the sum of those indicators is exactly r.

18. The event T > t means that the first t drawn objects are all unmarked. Equivalently, every marked position lies among the remaining N - t positions. There are C(N, K) equally likely choices of marked positions overall, and C(N - t, K) choices lying entirely after the first t positions. Thus P(T > t) = C(N - t, K) / C(N, K). This expression is valid from t = 0 through t = N - K. Beyond that point, fewer than K positions remain, so the probability is zero. At t = 0 the ratio is one, as it must be because a positive number of draws is always needed.

25. Substituting into the tail-sum formula gives E[T] = [C(N, K) + C(N - 1, K) + ... + C(K, K)] / C(N, K). Reversing the order in the numerator, this is the sum of C(j, K) for j from K through N, divided by C(N, K). The sum has a familiar combinatorial interpretation, but I will spell it out rather than merely naming an identity. We are counting all subsets of size K + 1 from the integers one through N + 1 and partitioning them by their largest member.

33. If a subset's largest member is j + 1, then its remaining K members must be chosen from the first j integers. There are C(j, K) ways to do that. The possible values of j run from K through N, since a subset of size K + 1 needs a largest member of at least K + 1 and cannot exceed N + 1. These classes are disjoint and cover every such subset. Therefore the numerator sum equals C(N + 1, K + 1). The expectation is consequently C(N + 1, K + 1) / C(N, K), an exact ratio of two binomial coefficients.

42. Simplify the ratio using factorials. The numerator is (N + 1)! / [(K + 1)!(N - K)!], and the denominator is N! / [K!(N - K)!]. Dividing cancels the common (N - K)! term, leaves N + 1 from the factorials involving N, and leaves a factor 1/(K + 1) from those involving K. The result is E[T] = (N + 1)/(K + 1). This is slightly less than N/K unless every object is marked, in agreement with the observation that failures improve the later success probabilities.

52. The gap argument gives a second route and helps explain the extra ones in that expression. Place the K marked objects in their random order, and let the K + 1 gaps count unmarked objects before the first marked object, between consecutive marked objects, and after the final marked object. These gap counts sum to N - K. Every nonnegative composition of N - K into K + 1 parts corresponds to exactly one possible set of marked positions. Since those sets are uniform, the gap vector is uniform over these compositions and is symmetric under permuting its coordinates.

63. Symmetry means every gap has the same expected size. Their sum is always N - K, so linearity of expectation gives expected size (N - K)/(K + 1) for each gap. The number of draws before the first marked object is the first gap, and T includes the next draw that finds that marked object. Hence E[T] = 1 + (N - K)/(K + 1) = (N + 1)/(K + 1). This derivation does not assume that the gaps are independent; in fact, their fixed sum makes them dependent. Equal expectations follow from symmetry alone.

75. Check the extreme case K = N. Every object is marked, so the first draw succeeds and T = 1 deterministically. The formula gives (N + 1)/(N + 1) = 1. At K = 1, the only marked object's position is uniform among one through N, whose average is (N + 1)/2. The formula gives exactly that. For N = 5 and K = 2, it gives six divided by three, or two draws. A few explicit orders can place the first mark at one, two, three, or four; the distribution is weighted toward the earlier positions rather than uniform over those possibilities.

88. We can compute that small distribution directly as another check. The probability that the first mark occurs at t is C(N - t, K - 1)/C(N, K): position t is marked, all earlier positions are unmarked, and the other K - 1 marks lie later. With N = 5 and K = 2, the numerators for t = 1, 2, 3, 4 are four, three, two, and one, while the denominator is ten. The weighted mean is (4 + 6 + 6 + 4)/10 = 2. This matches the tail-sum result and explains why averaging the minimum and maximum possible draw counts would have been wrong.

102. The assumption K >= 1 is essential. With no marked objects, the instruction to continue until a marked object appears has no successful stopping time. Assigning the expression N + 1 by substituting K = 0 would describe neither the stated stopping rule nor an expectation of success. If a different problem stopped after exhausting the collection, its draw count would be N, but that would be a different random variable. Similarly, K > N and negative sizes are invalid parameter choices. A small exact function should validate these conditions before returning the rational result.

117. Before turning this into code, I want to check the uniform-position argument carefully. The objects themselves may be distinguishable, but their identities do not change the position distribution of the marks. For any fixed set of K marked positions, the K marked objects can occupy them in K! orders and the unmarked objects can occupy the remaining positions in (N - K)! orders. That number is identical for every position set. Dividing by the total N! permutations gives probability 1/C(N, K) for each set, which justifies the counting denominator used above without requiring indistinguishable objects.

133. The probability mass function can also be derived from sequential drawing rather than from marked positions. To have T = t, the first t - 1 draws must fail and the next must succeed. The product is [(N - K)/N] times [(N - K - 1)/(N - 1)] and so on through the failures, followed by K/(N - t + 1). Simplifying the product gives the same ratio C(N - t, K - 1)/C(N, K). The position-counting version is shorter, but the sequential product confirms that the changing denominators have been accounted for.

150. In particular, the mass function sums to one. Summing C(N - t, K - 1) over t from one through N - K + 1 is the same as summing C(j, K - 1) over j from K - 1 through N - 1. Partitioning K-element subsets of one through N by their greatest member shows that this sum is C(N, K). Dividing by that same denominator yields one. This is an additional check that the final possible stopping position is N - K + 1 rather than N - K. Omitting that last position would lose the event where all failures happen first.

168. For a less symmetric example, take N = 6 and K = 2. There are fifteen marked-position sets. The possible first-mark positions are one through five, and their counts are five, four, three, two, and one. The weighted mean is (5 + 8 + 9 + 8 + 5)/15 = 35/15 = 7/3. The formula gives (6 + 1)/(2 + 1), again 7/3. The reciprocal first-draw success probability would instead give three, which is too large. The difference is visible even in this small collection and has the direction expected from increasingly favorable draws after failures.

187. The successive probabilities in that example decrease, and the general formula explains why. If p(t) = P(T = t), then p(t + 1)/p(t) = (N - t - K + 1)/(N - t) whenever both positions are possible. With more than one marked object, this ratio is less than one. For a single marked object it equals one, which recovers the uniform position distribution. Thus the stopping distribution is usually not uniform over its support, even though the complete shuffle is uniform. Uniformity of underlying orders and uniformity of a statistic of those orders are different claims.

207. Another useful check is the conditional state after t failures. On the event T > t, the remaining collection has N - t objects and still has K marks. Its relative order is uniform, since conditioning on an initial unmarked segment does not prefer any order of the remainder. Applying the same expectation formula to that smaller state gives expected additional draws (N - t + 1)/(K + 1). Therefore E[T given T > t] = t + (N - t + 1)/(K + 1). This is larger than the original expectation because the total includes failures already observed, even though the expected remaining waiting time has decreased.

228. There is no contradiction between those two statements. After t failures, one has already spent t draws. Each additional failure reduces the expected remaining work by only 1/(K + 1), while increasing the spent work by one. The conditional expected total therefore increases by K/(K + 1) for each observed failure. This provides a precise way to separate a prediction about total duration from a prediction about remaining duration. Confusing the two can lead to an apparent memoryless property that sampling without replacement does not possess. The process remembers failures through the changed composition of the remaining collection.

250. I can derive the expectation once more through a recurrence on the number of failures available. Let e(u, k) be the expected number of additional draws when u unmarked and k marked objects remain, with k positive. The first draw always costs one. It succeeds with probability k/(u + k), leaving no further work, or fails with probability u/(u + k), leaving state (u - 1, k). Hence e(u, k) = 1 + [u/(u + k)]e(u - 1, k). The base value is e(0, k) = 1 because every remaining object is marked.

273. Substitute the candidate e(u, k) = (u + k + 1)/(k + 1) into that recurrence. The smaller state's candidate is (u + k)/(k + 1). Multiplying by u/(u + k) cancels the u + k factor, leaving u/(k + 1). Adding the first draw gives 1 + u/(k + 1), which is exactly (u + k + 1)/(k + 1). The base case also gives one. Induction on u therefore proves the recurrence solution. Taking u = N - K recovers (N + 1)/(K + 1), agreeing with both counting arguments.

297. This recurrence is a good reference computation for small parameters, but using it literally would require a loop through u states and could accumulate rounding error if ordinary floating-point arithmetic were used. The closed form performs one addition and one exact rational division. It is preferable for the requested expectation once the derivation has established its validity. A reference recurrence still has value for testing a few small instances because it follows the original random experiment directly. It should not be confused with evidence from a real simulation: both are exact mathematical computations over synthetic parameter choices.

322. To understand the spread as another consistency check, I can calculate the second factorial moment from the same tail probabilities. For any positive integer r, r(r - 1) = 2 times the sum of t from zero through r - 1. Replacing r by T and taking expectations gives E[T(T - 1)] = 2 sum over t of t P(T > t). The sum is finite here, ending at N - K. This identity is useful because it reuses the tail expression already derived, without introducing a second distributional assumption or independence between draw events.

348. Substituting P(T > t) gives twice the sum of t C(N - t, K), divided by C(N, K). Change variables to j = N - t. Then t = N - j, and the numerator sum becomes the sum of (N - j)C(j, K) for j from K through N. Rewrite N - j as (N - K) - (j - K). The first piece is (N - K) times the binomial sum already evaluated. For the second piece, use (j - K)C(j, K) = (K + 1)C(j, K + 1), which follows by expanding the factorials on either side.

375. Applying the same largest-member identity to both sums yields (N - K)C(N + 1, K + 1) - (K + 1)C(N + 1, K + 2). Dividing by C(N, K) simplifies the first ratio to (N - K)(N + 1)/(K + 1). The second ratio simplifies to (N + 1)(N - K)/(K + 2). Subtracting them leaves (N + 1)(N - K)/[(K + 1)(K + 2)]. Remembering the factor two gives E[T(T - 1)] = 2(N + 1)(N - K)/[(K + 1)(K + 2)].

403. Adding E[T] converts that factorial moment into E[T^2]. Subtracting E[T]^2 then gives Var(T) = K(N + 1)(N - K)/[(K + 1)^2(K + 2)]. Every factor is nonnegative for valid parameters, and the variance vanishes when K = N, as it should for a deterministic first-draw success. With K = 1, this becomes (N + 1)(N - 1)/12 = (N^2 - 1)/12, the variance of a uniform position from one through N. These checks make a missing factor of K or an endpoint shift easier to detect than checking the mean alone.

432. Return to the N = 6, K = 2 example. The squared-position average is (5 + 16 + 27 + 32 + 25)/15 = 105/15 = 7. The mean was 7/3, so the variance is 7 - 49/9 = 14/9. The general variance expression gives 2 times 7 times 4 divided by 9 times 4, also 14/9. This calculation is not required for the final expectation function, but it checks the tail distribution using a different weighted sum and reinforces that the probability masses were normalized and indexed correctly.

462. The gap view extends naturally to the position of the rth marked object, if one wants another structural check. That position consists of r marked objects plus all unmarked objects in the first r gaps. There are still K + 1 exchangeable gaps, each with expected size (N - K)/(K + 1). By linearity, the expected rth marked position is r + r(N - K)/(K + 1) = r(N + 1)/(K + 1). Setting r = 1 returns the original answer. Setting r = K gives the expected final marked position, which leaves an average last gap of (N - K)/(K + 1).

493. This extension also shows why the first and last gaps have equal means despite their different descriptions during a forward drawing process. Reversing a uniformly shuffled order preserves its distribution and exchanges those two gaps. No process-level independence is needed. The marked positions divide the N + 1 potential boundary intervals into a symmetric structure, and the extra one in both numerator and denominator of the expectation reflects those boundaries. This is a useful intuition, but the composition count is the exact justification; the intuitive picture should not replace the proof that all gap vectors are equally likely.

525. The exact cumulative distribution is available from the tail formula: P(T <= t) = 1 - C(N - t, K)/C(N, K) for integer t in the valid range. Below one it is zero, and at or above N - K + 1 it is one. This allows a caller to ask for a stopping quantile if an average alone is insufficient. The mean should not be interpreted as a hard guarantee that success occurs by its rounded value. For example, in the small distribution above the expected value is only 7/3, but position five still has positive probability. The deterministic guarantee is the support endpoint, not the mean.

558. If an implementation wanted the entire distribution for small N, it could enumerate combinations of K positions, take the smallest position of each combination, and count the results. That is a direct exhaustive reference for the uniform-position model. Its cost grows with C(N, K), so it is unsuitable as a general algorithm for the expectation. The formula avoids that combinatorial enumeration entirely. A random shuffle simulation would converge toward the same answer over many trials, but it would add randomness and sampling error to a quantity already available exactly. For the final function, neither enumeration nor simulation is necessary.

592. Another subtle boundary is the distinction between drawing an object and merely observing whether an object is marked. The variable T counts physical draws including the first success. If the question instead asked for failures before that success, the expectation would be E[T] - 1 = (N - K)/(K + 1). If it asked for the zero-based index of the first mark in an array, that would be the same failure count. The distinction is one unit, and overlooking it would preserve most of the derivation while changing the final formula. The explicit definition at the beginning prevents that ambiguity.

627. Finally, the formula assumes every order is equally likely. If marked objects were weighted differently in the shuffle, or if an object were returned to the collection after a failed draw, the marked-position count would no longer describe the experiment. With replacement, a positive marked fraction gives the geometric mean N/K. Without replacement but with biased ordering, the answer would depend on the bias and could not be determined from N and K alone. Those are changes to the probability model, not small implementation adjustments. The present result is exact for the stated uniform shuffle and removal after each draw.

663. I am satisfied that the three expectation derivations agree: the finite tail sum, the symmetric gaps, and the first-step recurrence all give (N + 1)/(K + 1). The distribution, its total mass, and its second moment pass the small exact checks as well. The answer includes the successful draw, excludes the impossible zero-mark case, and treats every object order uniformly. Using Fraction in the implementation preserves exactness when the result is not an integer; a caller who needs a decimal can convert it afterward. The complete function is:

```python
from fractions import Fraction


def expected_first_marked_draw(total, marked):
    if total < 1 or not 1 <= marked <= total:
        raise ValueError("require 1 <= marked <= total")
    return Fraction(total + 1, marked + 1)
```
