val items = listOf("xyzw", "rgba", "stpq").map { it.toCharArray() } val map = mutableMapOf>>() for (firstChar in 0..3) { for (secondChar in 0..3) { val char2 = listOf(firstChar, secondChar) map.getOrPut(char2.max()!!, ::mutableSetOf).add(char2) for (thirdChar in 0..3) { val char3 = listOf(firstChar, secondChar, thirdChar) map.getOrPut(char3.max()!!, ::mutableSetOf) .add(char3) for (fourth in 0..3) { val char4 = listOf(firstChar, secondChar, thirdChar, fourth) map.getOrPut(char4.max()!!, ::mutableSetOf) .add(char4) } } } } for ((dim, nrs) in map) { if (dim != 1) { println("Vec${maxOf(dim + 1, 2)} ->") } for (item in nrs) { for (set in items) { println( " val ${item.map(set::get).joinToString("")}\n get() = KVec${item.size}(${item.map(items[0]::get) .joinToString(",")})\n" ) } } }