Skip to content

Instantly share code, notes, and snippets.

Created May 9, 2013 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5550057 to your computer and use it in GitHub Desktop.
Save anonymous/5550057 to your computer and use it in GitHub Desktop.
(defn lazy-compare
[& s]
(-> (some #{-1 1} (apply map compare s)) (or 0)))
(defn canonical?
[cards]
(if (not (= (sort cards) cards))
false
(let [by-suits (reduce (fn [a-map suit]
(let [new-val (for [card cards
:when (and (>= card suit)
(< card (+ suit 13)))]
(mod card 13))]
(if (= (count (into #{} new-val)) (count new-val))
(merge-with concat a-map {suit new-val})
(reduced false))))
{}
(range 0 52 13))]
(and by-suits
(not-any? (fn [suit]
(let [suit1 (by-suits (- suit 13))
suit2 (by-suits suit)]
(and (not (empty? suit2))
(or (< (count suit1) (count suit2))
(and (= (count suit1) (count suit2))
(pos? (lazy-compare suit1 suit2)))))))
(range 13 52 13))))))
(defn generate-isomorphs
[n]
(filter canonical? (c/combinations (range 52) n)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment