object Sieve { fun primesUpTo(upperBound: Int): List { val primes = mutableListOf() var candidates = (2..upperBound).toList() while (candidates.size > 0) { val prime = candidates[0] primes += prime candidates = candidates.filterIndexed { index, value -> index != 0 && value % prime != 0 } } return primes } }