Advertisement
Guest User

Untitled

a guest
Jul 16th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.56 KB | None | 0 0
  1. func kangaroo(x1: Int, v1: Int, x2: Int, v2: Int) -> String {
  2.     var currentLocation1 = x1
  3.     var currentLocation2 = x2
  4.     guard v2 < v1 else { return "NO" }
  5.    
  6.     while(differenceInLocations >= 0) {
  7.         if differenceInLocations == 0 {
  8.             return "YES"
  9.         }
  10.         currentLocation1 = currentLocation1 + v1
  11.         currentLocation2 = currentLocation2 + v2
  12.         if differenceInLocations > currentLocation2 - currentLocation1 {
  13.             differenceInLocations = currentLocation2 - currentLocation1
  14.     }
  15.        
  16.     return "NO"
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement