zvoulgaris

Decreasing-Increasing Order drill

May 29th, 2020
656
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Decreasing-increasing order drill
  2.  
  3. function IsInDecreasingOrder(dx::Array{Int64, 1})
  4.     OK = false
  5.  
  6.     for d in dx
  7.         if d > 0; return false; end
  8.         if d < 0; OK = true; end
  9.     end
  10.  
  11.     return OK
  12. end
  13.  
  14. function IsInIncreasingOrder(dx::Array{Int64, 1})
  15.     OK = false
  16.  
  17.     for d in dx
  18.         if d < 0; return false; end
  19.         if d > 0; OK = true; end
  20.     end
  21.  
  22.     return OK
  23. end
  24.  
  25. function main(x::Array{Int64, 1})
  26.     dx = diff(x)
  27.  
  28.     for i = 1:(length(dx)-1)
  29.         dx1 = dx[1:i]
  30.  
  31.         if IsInDecreasingOrder(dx1)
  32.             dx2 = dx[(i+1):end]
  33.             if IsInIncreasingOrder(dx2); return true, x[i]; end
  34.         end
  35.     end
  36.  
  37.     return false, NaN
  38. end
RAW Paste Data