Last active
December 25, 2015 17:19
-
-
Save jacekkolodziejski/7012173 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
object S99_P16 { | |
def drop[T](n: Int, ts: Seq[T]): Seq[T] = { | |
var iter = 0; | |
def op(el: T): Boolean = { iter = iter + 1; (iter % n != 0) } | |
ts filter op | |
} | |
def drop[T](n: Int, ts: Seq[T]): Seq[T] = | |
for (e <- ts.zipWithIndex if (e._2 + 1) % n != 0) yield e._1 | |
def drop[T](n: Int, ts: Seq[T]): Seq[T] = { | |
def everyN(e: (T, Int)): Boolean = ((e._2 + 1) % n) != 0 | |
ts.zipWithIndex.filter(everyN).map(_._1) | |
} | |
def drop[T](n: Int, ts: Seq[T]): Seq[T] = | |
ts.grouped(n).flatMap(_.take(n - 1)).toList | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment