Skip to content

Instantly share code, notes, and snippets.

@baens
Created March 30, 2018 12:19
Show Gist options
  • Save baens/0054d6af6515a90305d4d4d2a9599185 to your computer and use it in GitHub Desktop.
Save baens/0054d6af6515a90305d4d4d2a9599185 to your computer and use it in GitHub Desktop.
cc-2018-03-30
infix fun Int.toThePowerOf(exponent: Int): Int = Math.pow(this.toDouble(), exponent.toDouble()).toInt()
fun main(args: Array<String>) {
val sets = mutableListOf<Set<String>>()
sets.add(emptySet())
for(setNumber in 1 until 2.toThePowerOf(args.size)) {
val set = mutableSetOf<String>()
for(itemNumber in 0 until args.size) {
if (2 toThePowerOf itemNumber and setNumber != 0) {
set.add(args[itemNumber])
}
}
sets.add(set)
}
println(sets)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment