Skip to content

Commit 51b11a6

Browse files
committed
index-combinations now based on Alg T
1 parent 4b6ff30 commit 51b11a6

File tree

1 file changed

+2
-21
lines changed

1 file changed

+2
-21
lines changed

src/main/clojure/clojure/math/combinatorics.clj

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -71,26 +71,7 @@ Most of these algorithms are derived from algorithms found in Knuth's wonderful
7171
"
7272
)
7373

74-
(defn- index-combinations
75-
[n cnt]
76-
(lazy-seq
77-
(let [c (vec (cons nil (for [j (range 1 (inc n))] (+ j cnt (- (inc n)))))),
78-
iter-comb
79-
(fn iter-comb [c j]
80-
(if (> j n) nil
81-
(let [c (assoc c j (dec (c j)))]
82-
(if (< (c j) j) [c (inc j)]
83-
(loop [c c, j j]
84-
(if (= j 1) [c j]
85-
(recur (assoc c (dec j) (dec (c j))) (dec j)))))))),
86-
step
87-
(fn step [c j]
88-
(cons (rseq (subvec c 1 (inc n)))
89-
(lazy-seq (let [next-step (iter-comb c j)]
90-
(when next-step (step (next-step 0) (next-step 1)))))))]
91-
(step c 1))))
92-
93-
(defn- index-combinations2 ;Algorithm T
74+
(defn- index-combinations ;Algorithm T
9475
[n cnt]
9576
(lazy-seq
9677
(let [c (vec (concat [nil]
@@ -125,7 +106,7 @@ Most of these algorithms are derived from algorithms found in Knuth's wonderful
125106
(= n 1) (for [item items] (list item))
126107
(= n cnt) (list (seq items))
127108
:else
128-
(map #(map v-items %) (index-combinations2 n cnt)))))))
109+
(map #(map v-items %) (index-combinations n cnt)))))))
129110

130111
(defn- unchunk
131112
"Given a sequence that may have chunks, return a sequence that is 1-at-a-time

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy