Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. (defn displace [v left right x where]
  2. (let [y (subvec v 0 left) ; levo od nego
  3. z (subvec v right) ; desno od nego
  4. removed (apply conj y z) ; celiot vektor bez delot za premestuvanje
  5. left-vec (subvec removed 0 where)
  6. right-vec (subvec removed where)
  7. ]
  8. (apply conj (apply conj left-vec x) right-vec)
  9. )
  10. )
  11.  
  12. (defn displacement [v]
  13. (let [a (int (rand numcities))
  14. b (int (rand numcities))
  15. left (min a b) ;leva granica
  16. right (max a b) ;desna granica
  17. size (- right left)
  18. where (int (rand (- numcities size)))
  19. x (subvec v left right)
  20. ]
  21. (displace v left right x where)
  22. )
  23. )
  24.  
  25. (defn swap [v i1 i2]
  26. (assoc v i2 (v i1) i1 (v i2)))
  27.  
  28. (defn exchange [v]
  29. (let [a (int (rand numcities))
  30. b (int (rand numcities))]
  31. (swap v a b)
  32. )
  33. )
  34.  
  35. (defn insertion [v]
  36. (let [left (int (rand numcities))
  37. right (inc left)
  38. where (int (rand numcities))
  39. x (subvec v left right)
  40. ]
  41. (displace v left right x where)
  42. )
  43. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement