Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.44 KB | None | 0 0
  1. def mergeMatch(limit: Int)(a: Seq[Int], b: Seq[Int]): Int = {
  2.  
  3.   def mergeRec(limit: Int, a: Seq[Int], b: Seq[Int], acc: Int): Int = {
  4.     (a,b) match {
  5.       case (_, Nil) | (Nil, _) => acc
  6.       case (x +: xs, y +: ys) => if(Math.abs(x-y) < limit) mergeRec(limit, xs, ys, acc+1) else {
  7.         if(x < y) mergeRec(limit, xs, y +: ys, acc)
  8.         else mergeRec(limit, x +: xs, ys, acc)
  9.       }
  10.     }
  11.   }
  12.  
  13.   mergeRec(limit, a, b, 0)
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement