Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
27
Task/Knuths-algorithm-S/Kotlin/knuths-algorithm-s-2.kts
Normal file
27
Task/Knuths-algorithm-S/Kotlin/knuths-algorithm-s-2.kts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// version 1.2.51
|
||||
|
||||
import java.util.Random
|
||||
|
||||
val rand = Random()
|
||||
|
||||
fun <T> SOfNCreator(n: Int): (T) -> List<T> {
|
||||
val sample = ArrayList<T>(n)
|
||||
var i = 0
|
||||
return {
|
||||
if (++i <= n)
|
||||
sample.add(it)
|
||||
else if (rand.nextInt(i) < n)
|
||||
sample[rand.nextInt(n)] = it
|
||||
sample
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val bin = IntArray(10)
|
||||
(1..100_000).forEach {
|
||||
val sOfn = SOfNCreator<Int>(3)
|
||||
for (d in 0..8) sOfn(d)
|
||||
for (s in sOfn(9)) bin[s]++
|
||||
}
|
||||
println(bin.contentToString())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue