Skip to content

Commit aa3aa4d

Browse files
committed
core.logic: finally it works on a very simple task
1 parent 71daf2e commit aa3aa4d

File tree

2 files changed

+54
-42
lines changed

2 files changed

+54
-42
lines changed

clojure/project.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(defproject icfpc2025 "1.0.0-SNAPSHOT"
22
:description "Escape from ICFPC-2025"
3-
:dependencies [[org.clojure/clojure "1.4.0"]
4-
[org.clojure/core.logic "0.7.5"]]
3+
:dependencies [[org.clojure/clojure "1.12.2"]
4+
[org.clojure/core.logic "1.1.0"]]
55
:main icfpc2025.main)

clojure/src/icfpc2025/main.clj

Lines changed: 52 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -31,47 +31,55 @@
3131
(def room-number-range (range room-count))
3232
(def door-number-range (range door-in-room-count))
3333

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."
3636
[all-rooms room]
3737
(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
6455
[(== (: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+
)
6876
)
6977
)
7078
)
7179
)
7280
)
7381
)
74-
)
82+
]
7583
)
7684
)
7785
)
@@ -85,21 +93,25 @@
8593
(with-room room0
8694
(with-room room1
8795
(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)
90100

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
92105

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+
)
97109
)
98110
)
99111
)
100112
)
101113
)
102114

103115
(defn -main [& args]
104-
(println (do-solve))
116+
(pprint (do-solve))
105117
)

0 commit comments

Comments
 (0)