Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;This assumes a 1-D vector of 36 elements to represent a 6x6 grid.
- ;;start-point must be one of the corners of the grid, that is, 0, 5, 30, or 35.
- ;;target can be any other number less than 36, and represents an index.
- (defn path-to-target [start-point target]
- (loop [confirmed-squares []
- current-square start-point]
- (if (= current-square target)
- confirmed-squares
- (recur (conj confirmed-squares current-square)
- (cond
- (< 0 (- (rem current-square 6) (rem target 6))) (inc current-square)
- (> 0 (- (rem current-square 6) (rem target 6))) (dec current-square)
- :else (cond
- (< 0 (- (quot current-square 6) (quot target 6))) (+ 6 current-square)
- (> 0 (- (quot current-square 6) (quot target 6))) (- 6 current-square)
- :else target))
- ))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement