Created
November 12, 2014 05:32
-
-
Save siosio/c6055e350a7e34be0b7d to your computer and use it in GitHub Desktop.
a.get(i + 1)で落ちる(´・ω・`)
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
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