Advertisement
Guest User

Untitled

a guest
Jul 7th, 2010
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.71 KB | None | 0 0
  1. (defn aswap! [array i j]
  2.   (let [ai (aget array i)
  3.         aj (aget array j)]
  4.     (aset array i aj)
  5.     (aset array j ai)))
  6.  
  7. (defn drive-to! [array n]
  8.   (doseq [i (range 0 n)]
  9.     (aswap! array i (inc i))))
  10.  
  11. (defn move-elements-to-the-end [array n]
  12.   (loop [i 1, dest (dec (alength array))]
  13.     (when (<= i n) (do (drive-to! array dest)
  14.                        (recur (inc i) dest))))
  15.   array)
  16.  
  17. дебаг
  18. (1 2 3 4 5 6 7)
  19. (2 1 3 4 5 6 7)
  20. (2 3 1 4 5 6 7)
  21. (2 3 4 1 5 6 7)
  22. (2 3 4 5 1 6 7)
  23. (2 3 4 5 6 1 7)
  24. (2 3 4 5 6 7 1)
  25. (3 2 4 5 6 7 1)
  26. (3 4 2 5 6 7 1)
  27. (3 4 5 2 6 7 1)
  28. (3 4 5 6 2 7 1)
  29. (3 4 5 6 7 2 1)
  30. (3 4 5 6 7 1 2)
  31. (4 3 5 6 7 1 2)
  32. (4 5 3 6 7 1 2)
  33. (4 5 6 3 7 1 2)
  34. (4 5 6 7 3 1 2)
  35. (4 5 6 7 1 3 2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement