Created
January 26, 2020 04:28
-
-
Save pavi2410/5a1c1623831f54b59de891dd0e26f637 to your computer and use it in GitHub Desktop.
Pizza Hashcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val max = 17 | |
val numTypes = 4 | |
val types = listOf(2, 5, 6, 8) | |
fun main() { | |
val r = types.mapIndexed { i, t -> i to t } | |
.sortedByDescending { (i, t) -> t } | |
val f = mutableListOf<Int>() | |
var k = 0 | |
for ((i, t) in r) { | |
if ( k + t <= max) { | |
k += t | |
f += i | |
} | |
} | |
print(f.sortedBy { it }) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://pl.kotl.in/8nrN7dDFs