File tree 1 file changed +9
-4
lines changed
1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change 8
8
(push b (gethash a before-than))))
9
9
(mapcar #' extract-positive-integers updates))))
10
10
11
- ; ; The problem description clearly states that any ordering rule involving pages
12
- ; ; not included in the update should not be included, so we just have to rely
13
- ; ; on the explicit rules, without any recursion.
11
+
12
+ ; ; By taking a good look at the input we can notice that for every pair of
13
+ ; ; pages p1 and p2 listed in any input page update, there exists an
14
+ ; ; **explicit** rule which either put p1 before p2 or p2 before p1. This means
15
+ ; ; we don't have to mess with recursion to figure out if p1 should be printed
16
+ ; ; before p2, or vice-versa.
14
17
(defun before? (rules p1 p2)
15
- (member p2 (gethash p1 rules)))
18
+ (aprog1 (member p2 (gethash p1 rules))
19
+ (assert (xor it
20
+ (member p1 (gethash p2 rules))))))
16
21
17
22
(defun correctly-ordered? (rules update)
18
23
(looping
You can’t perform that action at this time.
0 commit comments