Skip to content

Instantly share code, notes, and snippets.

@Engelberg
Created March 7, 2013 05:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Engelberg/5105820 to your computer and use it in GitHub Desktop.
Save Engelberg/5105820 to your computer and use it in GitHub Desktop.
Solving logic puzzle with rules in more efficient order
(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