Add a function to get all permutations for a block.
continuous-integration/drone/push Build is passing Details

dev 0.9.10
KKlochko 1 year ago
parent 6a1ecf93db
commit d1b2ddc351

@ -23,6 +23,13 @@
(map second)
(into [])))
(defn get-all-permutation-for-block
"Return a vector for all possible blocks that can be made from a vector of symbols."
[symbols]
(->> (comb/permutations symbols)
(map cs/join)
(into [])))
(defn get-possible-keys
"Return possible keys for a possible key vector. For example, if you have a map: {\\a [\\a \\b \\c] \\b [\\b \\c] \\c [\\a \\c]}, then the vector is [[\\a \\b \\c] [\\b \\c] [\\a \\c]] and keys (\"aba\" \"abc\" ...)."
[possible-key-vector]

@ -14,12 +14,19 @@
{\a [\a \b] \c [\b \a] \b [\a \c]} "abc" [[\a \b] [\a \c] [\b \a]])))
(deftest get-possible-key-vector-from-reversed-count-map-test
(testing ""
(testing "The block order must be in descending order"
(are [reversed-count-map expected-key-vector]
(= expected-key-vector (get-possible-key-vector-from-reversed-count-map reversed-count-map))
{1 [\a \c] 2 [\b]} [[\b] [\a \c]]
{2 [\a] 1 [\b] 3 [\c]} [[\c] [\a] [\b]])))
(deftest get-all-permutation-for-block-test
(testing "It must return all permutations"
(are [symbols expected-permutations]
(= expected-permutations (get-all-permutation-for-block symbols))
[\a \b] ["ab" "ba"]
[\a \b \c] ["abc" "acb" "bac" "bca" "cab" "cba"])))
(deftest get-possible-keys-test
(testing "The keys must be the all combinations"
(are [possible-keys-vector expected-keys]

Loading…
Cancel
Save