daily pastebin goal
30%
SHARE
TWEET

Untitled

a guest Mar 22nd, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top