-
Notifications
You must be signed in to change notification settings - Fork 1
/
vienna.clj
34 lines (30 loc) · 985 Bytes
/
vienna.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
;; This code was worked out in a group to start solving a small
;; portion of a Viennese maze, specifically the 4 top left nodes (a, b, e, f)
;; of the square maze at https://i.imgur.com/j2gWurM.jpg
;;
;; The code below can get the bicyclist home... ignoring important constraints.
;; It lacks error handling, name spacing, and pull requests to add all that.
;;
;; Blog post for more details on a Viennese Maze: http://zulko.github.io/blog/2014/04/27/viennese-mazes-what-they-are/
;; it's a map! it's a function!
(def next-light
{:g :y
:y :r
:r :g})
(def world
{:location :a
:nodes {#{:a :b} :y
#{:a :e} :g
#{:b :f} :g
#{:f :e} :g}})
(defn map-vals
[m f]
(reduce-kv (fn [a k v] (assoc a k (f v))) {} m))
(defn move-to [world new-location]
(-> world
(assoc
:last-location (:location world)
:location new-location)
(update-in
[:nodes]
(fn [nodes] (map-vals nodes next-light)))))