Skip to content

Instantly share code, notes, and snippets.

@ajozwik
Last active December 25, 2015 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajozwik/7012102 to your computer and use it in GitHub Desktop.
Save ajozwik/7012102 to your computer and use it in GitHub Desktop.
def drop[T](n: Int, ts: Seq[T]): Seq[T] =
ts.foldLeft((n, Seq[T]()))((acc, t) => {
val (x, ts) = acc
if (x == 1) (n, ts) else (x - 1, ts :+ t)
})._2
def p16[T](nr: Int, list: Seq[T]): Seq[T] = {
def p16( list: Seq[T], index: Int, acc: Seq[T]): Seq[T] = list match {
case Nil => acc
case h :: t if (nr == index) => p16( t, 1, acc)
case h :: t => p16( t, index + 1, acc :+ h)
}
p16( list, 1, Nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment