|
31 | 31 | (def room-number-range (range room-count)) |
32 | 32 | (def door-number-range (range door-in-room-count)) |
33 | 33 |
|
34 | | -(defn setup-room |
35 | | - "General structure here: each door gets its own root conde block, containing a lot of conditions for each sub-door of each other room." |
| 34 | +(defn setup-roomo |
| 35 | + "General structure here: each door gets its own root block, containing a lot of conditions for each sub-door of each other room." |
36 | 36 | [all-rooms room] |
37 | 37 | (let [room-index (-> all-rooms (.indexOf room))] |
38 | | - (->> |
39 | | - (:doors room) |
40 | | - (map-indexed |
41 | | - (fn [door-index door] |
42 | | - (membero (:door door) door-number-range) |
43 | | - (membero (:room door) room-number-range) |
44 | | - (conde |
45 | | - (concat |
46 | | - (->> |
47 | | - all-rooms |
48 | | - (map-indexed |
49 | | - (fn [other-room-index other-room] |
50 | | - (if (= other-room-index room-index) |
51 | | - ; For room looping back to itself, all the doors should be short-circuited. |
52 | | - [ |
53 | | - [(== (:room door) other-room-index) |
54 | | - (== (:door door) door-index)] |
55 | | - ] |
56 | | - ; For the other room connected to the current door, generate a list of clauses about possible |
57 | | - ; connections to each of the other room's doors. |
58 | | - (->> |
59 | | - (:doors other-room) |
60 | | - (map-indexed |
61 | | - (fn [other-door-index other-door] |
62 | | - ; If the current door connects to the other room, corresponding door of the other room should |
63 | | - ; connect to here. |
| 38 | + (and* |
| 39 | + (->> |
| 40 | + (:doors room) |
| 41 | + (map-indexed |
| 42 | + (fn [door-index door] |
| 43 | + (and* |
| 44 | + [ |
| 45 | + (membero (:door door) door-number-range) |
| 46 | + (membero (:room door) room-number-range) |
| 47 | + (or* |
| 48 | + (->> |
| 49 | + all-rooms |
| 50 | + (map-indexed |
| 51 | + (fn [other-room-index other-room] |
| 52 | + (if (= other-room-index room-index) |
| 53 | + ; For room looping back to itself, all the doors should be short-circuited. |
| 54 | + (conde |
64 | 55 | [(== (:room door) other-room-index) |
65 | | - (== (:door door) other-door-index) |
66 | | - (== (:room other-door) room-index) |
67 | | - (== (:door other-door) door-index)] |
| 56 | + (== (:door door) door-index)] |
| 57 | + ) |
| 58 | + ; For the other room connected to the current door, generate a list of clauses about possible |
| 59 | + ; connections to each of the other room's doors. |
| 60 | + (or* |
| 61 | + (->> |
| 62 | + (:doors other-room) |
| 63 | + (map-indexed |
| 64 | + (fn [other-door-index other-door] |
| 65 | + ; If the current door connects to the other room, corresponding door of the other room |
| 66 | + ; should connect to here. |
| 67 | + (and* |
| 68 | + [(== (:room door) other-room-index) |
| 69 | + (== (:door door) other-door-index) |
| 70 | + (== (:room other-door) room-index) |
| 71 | + (== (:door other-door) door-index)] |
| 72 | + ) |
| 73 | + ) |
| 74 | + ) |
| 75 | + ) |
68 | 76 | ) |
69 | 77 | ) |
70 | 78 | ) |
71 | 79 | ) |
72 | 80 | ) |
73 | 81 | ) |
74 | | - ) |
| 82 | + ] |
75 | 83 | ) |
76 | 84 | ) |
77 | 85 | ) |
|
85 | 93 | (with-room room0 |
86 | 94 | (with-room room1 |
87 | 95 | (let [rooms [room0 room1]] |
88 | | - (setup-room rooms room0) |
89 | | - (setup-room rooms room1) |
| 96 | + (conde |
| 97 | + [ |
| 98 | + (setup-roomo rooms room0) |
| 99 | + (setup-roomo rooms room1) |
90 | 100 |
|
91 | | - (== rooms-q rooms) |
| 101 | + ; Now, concrete facts: |
| 102 | + (== (:doors room0) [{:door 0 :room 0} {:door 1 :room 1}]) |
| 103 | + (== (nth (:doors room1) 0) {:door 0 :room 1}) |
| 104 | + ; let the engine to guess where the door 1 from the room 1 connects to |
92 | 105 |
|
93 | | - ; Now, concrete facts: |
94 | | - (== (:doors room0) [{:door 0 :room 0} {:door 1 :room 1}]) |
95 | | - (== (nth (:doors room1) 0) {:door 0 :room 1}) |
96 | | - ; let the engine to guess where the door 1 from the room 1 connects to |
| 106 | + (== rooms-q rooms) |
| 107 | + ] |
| 108 | + ) |
97 | 109 | ) |
98 | 110 | ) |
99 | 111 | ) |
100 | 112 | ) |
101 | 113 | ) |
102 | 114 |
|
103 | 115 | (defn -main [& args] |
104 | | - (println (do-solve)) |
| 116 | + (pprint (do-solve)) |
105 | 117 | ) |
0 commit comments