Skip to content

Instantly share code, notes, and snippets.

@pavi2410
Created January 26, 2020 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pavi2410/5a1c1623831f54b59de891dd0e26f637 to your computer and use it in GitHub Desktop.
Save pavi2410/5a1c1623831f54b59de891dd0e26f637 to your computer and use it in GitHub Desktop.
Pizza Hashcode
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 })
}
@pavi2410
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment