fork download
  1.  
  2. object Main extends App {
  3. val xs= 1 to 20 toList
  4. def drop_odds(list:List[Int])=list.filter(_% 2==0)
  5. def filter_nth(list:List[Int],n:Int)=list.zipWithIndex.filter { case (_, i) => (i + 1) % n != 0 }.map { _._1}
  6. def reverse_two_halves(list:List[Int])=list.splitAt(list.length/2) match{case (left:List[Int],right:List[Int])=>right++left}
  7.  
  8.  
  9. println(drop_odds(xs))
  10. println(filter_nth(xs,3))
  11. println(reverse_two_halves(xs))
  12.  
  13. }
  14.  
Success #stdin #stdout 0.17s 322496KB
stdin
Standard input is empty
stdout
List(2, 4, 6, 8, 10, 12, 14, 16, 18, 20)
List(1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20)
List(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)