Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defn aswap! [array i j]
- (let [ai (aget array i)
- aj (aget array j)]
- (aset array i aj)
- (aset array j ai)))
- (defn drive-to! [array n]
- (doseq [i (range 0 n)]
- (aswap! array i (inc i))))
- (defn move-elements-to-the-end [array n]
- (loop [i 1, dest (dec (alength array))]
- (when (<= i n) (do (drive-to! array dest)
- (recur (inc i) dest))))
- array)
- дебаг
- (1 2 3 4 5 6 7)
- (2 1 3 4 5 6 7)
- (2 3 1 4 5 6 7)
- (2 3 4 1 5 6 7)
- (2 3 4 5 1 6 7)
- (2 3 4 5 6 1 7)
- (2 3 4 5 6 7 1)
- (3 2 4 5 6 7 1)
- (3 4 2 5 6 7 1)
- (3 4 5 2 6 7 1)
- (3 4 5 6 2 7 1)
- (3 4 5 6 7 2 1)
- (3 4 5 6 7 1 2)
- (4 3 5 6 7 1 2)
- (4 5 3 6 7 1 2)
- (4 5 6 3 7 1 2)
- (4 5 6 7 3 1 2)
- (4 5 6 7 1 3 2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement