= Solution
Use a strict record test; tying the previous record is not enough:
``
def emitHighlyComposite(): Unit = {
var candidate = 1
var best = 0
while (true) {
val count = divisors(candidate)
if (count > best) {
emit(candidate)
best = count
}
candidate += 1
}
}
``
At the start of an iteration, `best` is the <maximum> <divisor> count among the <positive integers> below `candidate`, taking the <maximum> of the empty family as zero. The already emitted values are exactly the <highly composite numbers> in that range, in increasing order. The next count exceeds `best` precisely when this candidate is a new strict record. Updating the record and advancing the candidate preserves both assertions. The program deliberately has no termination requirement; \b[<integer overflow> in this unbounded enumeration is ignored as directed by the source].
Back to article page