Skip to content

Instantly share code, notes, and snippets.

@siosio
Created November 12, 2014 05:32
Show Gist options
  • Save siosio/c6055e350a7e34be0b7d to your computer and use it in GitHub Desktop.
Save siosio/c6055e350a7e34be0b7d to your computer and use it in GitHub Desktop.
a.get(i + 1)で落ちる(´・ω・`)
package yank
fun runs(a: IntArray): Int {
return a.answer({(i: Int): Boolean -> i < a.size && a.get(i) != a.get(i + 1) })
}
fun IntArray.answer(filter: (i: Int) -> Boolean): Int {
var result =
when (this.size) {
0 -> 0
else -> 1
}
for (i in this.indices) {
if (filter(i)) {
result++
}
}
return result
}
fun main(args: Array<String>) {
println (runs(intArray(1, 2, 3, 2, 1)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment