File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change 2
2
(def LEFT 1 )
3
3
(def DOWN 2 )
4
4
(def RIGHT 3 )
5
- (def DIRECTIONS [UP RIGTH DOWN LEFT UP RIGHT ])
5
+ (def DIRECTIONS [UP RIGTH DOWN LEFT])
6
6
7
7
8
8
(def WALL 0 )
41
41
'((succ x), y))))))
42
42
43
43
(defn next [direction]
44
- (nth DIRECTIONS (succ direction)))
44
+ (if (== direction LEFT)
45
+ UP
46
+ (let [pos (lookup DIRECTIONS direction)]
47
+ (nth DIRECTIONS (succ pos)))))
45
48
46
49
(defn back [direction]
47
50
(if (== direction UP)
48
51
RIGHT
49
- (nth DIRECTIONS (pred direction))))
52
+ (let [pos (lookup DIRECTIONS direction)]
53
+ (nth DIRECTIONS (pred pos)))))
Original file line number Diff line number Diff line change 6
6
7
7
(defn pred [x]
8
8
(sub x 1 ))
9
+
10
+ (defn lookup [list elem]
11
+ (let [lookup-in (fn [l p]
12
+ (if (== (head l) elem)
13
+ p
14
+ (lookup-in (tail l) (succ p))))]
15
+ (lookup-in list 0 )))
You can’t perform that action at this time.
0 commit comments