@@ -489,7 +489,7 @@ output is nth-permutation (0-based)"
489
489
(defn- count-combinations-unmemoized
490
490
" We need an internal version that doesn't memoize each call to count-combinations-from-frequencies
491
491
so that we can memoize over a series of calls."
492
- [items t]
492
+ [items t]
493
493
(if (all-different? items)
494
494
(n-take-k (count items) t)
495
495
(count-combinations-from-frequencies (frequencies items) t)))
@@ -557,12 +557,12 @@ represented by freqs"
557
557
(defn nth-combination
558
558
" The nth element of the sequence of t-combinations of items"
559
559
[items t n]
560
- (binding [count-combinations-from-frequencies ( memoize count-combinations-from-frequencies)]
561
- ( assert ( < n ( count-combinations-unmemoized items t))
562
- ( format " %s is too large. Input has only %s combinations. "
563
- ( str n) ( str ( count-combinations-unmemoized items t))) )
564
- (if ( all-different? items)
565
- ( nth-combination-distinct items t n)
560
+ (assert ( < n ( count-combinations items t))
561
+ ( format " %s is too large. Input has only %s combinations. "
562
+ ( str n) ( str ( count- combinations-unmemoized items t))))
563
+ ( if ( all-different? items)
564
+ (nth-combination-distinct items t n )
565
+ ( binding [count-combinations-from-frequencies ( memoize count-combinations-from-frequencies)]
566
566
(let [v (vec (distinct items))
567
567
f (frequencies items),
568
568
indices (apply concat
@@ -573,10 +573,10 @@ represented by freqs"
573
573
574
574
(defn nth-subset
575
575
[items n]
576
+ (assert (< n (count-subsets items))
577
+ (format " %s is too large. Input has only %s subsets."
578
+ (str n) (str (count-subsets items))))
576
579
(binding [count-combinations-from-frequencies (memoize count-combinations-from-frequencies)]
577
- (assert (< n (count-subsets items))
578
- (format " %s is too large. Input has only %s subsets."
579
- (str n) (str (count-subsets-unmemoized items))))
580
580
(loop [size 0 ,
581
581
n n]
582
582
(let [num-combinations (count-combinations-unmemoized items size)]
0 commit comments