Recursively finding all partitions of a set of n objects into k non-empty subsets
问题 I want to find all partitions of a n elements into k subsets, this is my algorithm based on recursive formula for finding all Stirling second numbers fun main(args: Array<String>) { val s = mutableSetOf(1, 2, 3, 4, 5) val partitions = 3 val res = mutableSetOf<MutableSet<MutableSet<Int>>>() partition(s, partitions, res) //println(res) println("Second kind stirling number ${res.size}") } fun partition(inputSet: MutableSet<Int>, numOfPartitions: Int, result: MutableSet<MutableSet<MutableSet<Int>