Skip to content

Instantly share code, notes, and snippets.

@willf
Created July 17, 2013 14:30
Show Gist options
  • Save willf/6021087 to your computer and use it in GitHub Desktop.
Save willf/6021087 to your computer and use it in GitHub Desktop.
def countMonotonicityBreaks(items: Seq[Int]): Int =
items.sliding(2). // two items at a time
filter(p => p.size == 2 && p(0) != p(1)). // remove any equalities
map{p => p(1).compare(p(0))}. // get -1 and 1 values; must have 2 values
sliding(2). // take *these* two at a time
count(p => p.size == 2 && p(0) != p(1)) // count when the differ
@willf
Copy link
Author

willf commented Jul 17, 2013

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