findFirstGood

fun findFirstGood(high: Int, good: (n: Int) -> Boolean): Int

Flexible binary search implementation.

Function good is defined for ints from 0 to high-1. Find i such that (i == 0 || !good(i-1)) && (i == h || good(i)). In other words, good(i) is the "first" good = true.