This program calculates the “Birthday Problem” probabilities, determining how many people are needed in a group before there is at least a 50% chance that two or more share the same birthday. It iterates from 1 to 60 people, printing each group size alongside the running probability that at least two share a birthday. The probability complement is computed iteratively: Q accumulates the product of (365−N)/365 terms, representing the chance that all birthdays are distinct, and then (Q−1)×−100 converts this to a percentage chance of a collision. The SCROLL command is used to prevent the display from pausing, allowing all 60 results to stream continuously past.
Program Analysis
Program Structure
The program is a straightforward iterative calculation across six lines. It initialises a probability accumulator, loops from 1 to 60, and prints results continuously using SCROLL to avoid the display filling up.
| Line | Purpose |
|---|---|
10 | Prints a multi-line description of the problem |
20 | Initialises Q to 1 (the probability all birthdays are unique, starting condition) |
30 | Opens the main loop, N = group size from 1 to 60 |
40 | SCROLL prevents the display from pausing between lines |
50 | Prints N and the collision probability as a percentage |
60 | Updates Q by multiplying in the next distinct-birthday factor |
70 | Closes the loop |
Mathematical Approach
The Birthday Problem is solved using the complementary probability. Q holds the probability that all N people have distinct birthdays, computed as the running product:
Q = (365/365) × (364/365) × (363/365) × … × ((365−N+1)/365)
At each step, line 50 prints -(100*(Q-1)), which is equivalent to 100*(1-Q) — converting the complement probability into a percentage chance that at least two people share a birthday. The negation trick avoids the need for a separate subtraction from 1, since Q−1 is always negative or zero.
The classic result — that a group of 23 people suffices for a greater than 50% collision probability — will be clearly visible in the output around N=23.
Key BASIC Idioms
SCROLLat line40suppresses the scroll prompt, allowing all 60 lines of output to flow without user intervention.- The use of commas in the
PRINTstatement at line10advances to successive print zones, indenting the title text. - The expression
-(100*(Q-1))is a compact idiom for100*(1-Q), exploiting unary negation rather than rewriting the subtraction. Qis updated in place each iteration rather than recomputed from scratch, making this an efficient incremental calculation.
Notable Techniques
The iterative update of Q at line 60 — multiplying by (365-N)/365 — means the program never needs to compute a factorial or large product from scratch, keeping numerical operations within manageable floating-point range for all 60 iterations.
Bugs and Anomalies
The loop begins at N=1, for which the collision probability is 0% (one person cannot share a birthday with anyone else). This is mathematically correct but slightly redundant as a starting point. The loop runs to N=60, well past the point (~23) where probability exceeds 50%, which is useful for demonstrating how quickly the probability approaches certainty near N=60 (approximately 99.4%).
The title string on line 10 is not line-wrapped with explicit formatting — the text runs on as a single long string and relies on the display’s automatic wrapping, which may produce ragged output depending on screen width.
Content
Source Code
10 PRINT ,,"PROGRAM TO DETERMINE THE NUMBER OF PEOPLE NEEDED TO HAVE AT LEAST 50 PERCENT PROBABILITY OF HAVING TWO OR MORE WITH THE SAMEBIRTHDAY."
20 LET Q=1
30 FOR N=1 TO 60
40 SCROLL
50 PRINT N,-(100*(Q-1))
60 LET Q=Q*(365-N)/365
70 NEXT N
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
