Last active
August 29, 2015 14:09
-
-
Save siosio/3f82453f4543e007e0c0 to your computer and use it in GitHub Desktop.
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
data class Ret(val count:Int, val prev:Int?) { | |
fun next(number:Int) = if (prev == number) | |
Ret(count, number) | |
else | |
Ret(count + 1, number) | |
} | |
fun runs(a: IntArray): Int { | |
return a.fold(Ret(0, null), {(ret, num) -> | |
ret.next(num) | |
}).count | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment