Skip to content

Instantly share code, notes, and snippets.

@siosio
Last active August 29, 2015 14:09
Show Gist options
  • Save siosio/3f82453f4543e007e0c0 to your computer and use it in GitHub Desktop.
Save siosio/3f82453f4543e007e0c0 to your computer and use it in GitHub Desktop.
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