Created
March 7, 2013 05:52
-
-
Save Engelberg/5105820 to your computer and use it in GitHub Desktop.
Solving logic puzzle with rules in more efficient order
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn logic-puzzle [] | |
(let [people [:amaya :bailey :jamari :jason :landon]] | |
(for [[fortune time cosmopolitan us-weekly vogue] (permutations people) ; magazines | |
:when (not= fortune :jamari) | |
[asiago blue-cheese mascarpone mozzarella muenster] (permutations people) ; cheeses | |
:when (= blue-cheese fortune) | |
:when (not= muenster vogue) | |
reservations (permutations people) | |
:let [[five six seven seven-thirty eight-thirty] reservations] | |
:when (not= five time) | |
:when (= five mozzarella) | |
:when (#{seven seven-thirty} fortune) | |
:when (= (set [seven-thirty mozzarella]) (set [:landon :jason])) | |
:when (= (count (set [fortune :landon five mascarpone vogue])) 5) | |
:when (< (.indexOf reservations cosmopolitan) (.indexOf reservations mascarpone)) | |
:when (> (.indexOf reservations :bailey) (.indexOf reservations blue-cheese)) | |
:when (> (.indexOf reservations :landon) (.indexOf reservations time))] | |
(array-map | |
:fortune fortune :time time :cosmopolitan cosmopolitan :us-weekly us-weekly :vogue vogue | |
:asiago asiago :blue-cheese blue-cheese :mascarpone mascarpone :mozzarella mozzarella :muenster muenster | |
:five five :six six :seven seven :seven-thirty seven-thirty :eight-thirty eight-thirty)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment