Created
May 9, 2013 19:49
-
-
Save anonymous/5550057 to your computer and use it in GitHub Desktop.
This file contains 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 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