Created
November 17, 2012 16:42
-
-
Save kanterov/4097473 to your computer and use it in GitHub Desktop.
derivative in scala
This file contains hidden or 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
// 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