]> gitweb.factorcode.org Git - factor.git/commitdiff
math.combinatorics: add a word to get unique combinations using a hash-set
authorDoug Coleman <doug.coleman@gmail.com>
Sun, 7 Apr 2024 03:43:23 +0000 (22:43 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Sun, 7 Apr 2024 04:26:47 +0000 (23:26 -0500)
basis/math/combinatorics/combinatorics.factor

index 771dda2624b307e025b4e2db1631151ee32092eb..1d09824908e02d61b7424b70e16cfe0e4fb0a239 100644 (file)
@@ -2,8 +2,8 @@
 ! See https://factorcode.org/license.txt for BSD license.
 
 USING: accessors arrays assocs classes.tuple combinators hints
-kernel kernel.private make math math.functions math.order
-ranges sequences sequences.private sorting strings vectors ;
+kernel kernel.private make math math.functions math.order ranges
+sequences sequences.private sets sorting strings vectors ;
 IN: math.combinatorics
 
 <PRIVATE
@@ -301,6 +301,9 @@ PRIVATE>
 : all-combinations ( seq k -- seq' )
     [ ] map-combinations ;
 
+: all-unique-combinations ( seq n -- seq' )
+    HS{ } clone [ '[ _ adjoin ] each-combination ] keep members ;
+
 : all-combinations? ( ... seq k quot: ( ... elt -- ... ? ) -- ... ? )
     combinations-quot all? ; inline