Skip to content

Instantly share code, notes, and snippets.

@kanterov
Created November 17, 2012 16:42
Show Gist options
  • Save kanterov/4097473 to your computer and use it in GitHub Desktop.
Save kanterov/4097473 to your computer and use it in GitHub Desktop.
derivative in scala
// in scala
// https://twitter.com/my7truth/status/269825587797958656
// 79
def p1(p: Seq[Int]) = p.zipWithIndex.map{case (x,y) => x * (p.size - y - 1)} dropRight 1
// 86
def p2(p: Seq[Int]) = p.zipWithIndex.map(x => x._1 * (p.size - x._2 - 1)) dropRight 1
// 83
def p3(p: Seq[Int]) = p.reverse.zipWithIndex.map(x => x._1 * x._2).drop(1).reverse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment