@@ -8,16 +8,16 @@ namespace Algorithm.Sandbox.Combinatorics
88{
99 public class Permutation
1010 {
11- public static List < List < T > > Find < T > ( List < T > input , bool enableRepetition = false )
11+ public static List < List < T > > Find < T > ( List < T > input , bool withRepetition = false )
1212 {
1313 var result = new List < List < T > > ( ) ;
1414
15- Recurse ( input , enableRepetition , new List < T > ( ) , new HashSet < int > ( ) , result ) ;
15+ Recurse ( input , withRepetition , new List < T > ( ) , new HashSet < int > ( ) , result ) ;
1616
1717 return result ;
1818 }
1919
20- private static void Recurse < T > ( List < T > input , bool enableRepetition ,
20+ private static void Recurse < T > ( List < T > input , bool withRepetition ,
2121 List < T > prefix , HashSet < int > prefixIndices ,
2222 List < List < T > > result )
2323 {
@@ -29,39 +29,39 @@ private static void Recurse<T>(List<T> input, bool enableRepetition,
2929
3030 for ( int j = 0 ; j < input . Count ; j ++ )
3131 {
32- if ( prefixIndices . Contains ( j ) && ! enableRepetition )
32+ if ( prefixIndices . Contains ( j ) && ! withRepetition )
3333 {
3434 continue ;
3535 }
3636
3737 prefix . Add ( input [ j ] ) ;
3838 prefixIndices . Add ( j ) ;
3939
40- Recurse ( input , enableRepetition , prefix , prefixIndices , result ) ;
40+ Recurse ( input , withRepetition , prefix , prefixIndices , result ) ;
4141
4242 prefix . RemoveAt ( prefix . Count - 1 ) ;
4343 prefixIndices . Remove ( j ) ;
4444 }
4545 }
4646
47- public static List < List < T > > Find < T > ( List < T > input , bool enableRepetition ,
48- bool enableInversions ) where T : IComparable
47+ public static List < List < T > > Find < T > ( List < T > input , bool withRepetition ,
48+ bool withInversions ) where T : IComparable
4949 {
5050 var result = new List < List < T > > ( ) ;
5151
52- Recurse ( input , enableRepetition , enableInversions ,
52+ Recurse ( input , withRepetition , withInversions ,
5353 new List < T > ( ) , new HashSet < int > ( ) , result ) ;
5454
5555 return result ;
5656 }
5757
5858 private static void Recurse < T > ( List < T > input ,
59- bool enableRepetition , bool enableInversions ,
59+ bool withRepetition , bool withInversions ,
6060 List < T > prefix , HashSet < int > prefixIndices ,
6161 List < List < T > > result ) where T : IComparable
6262 {
6363 if ( prefix . Count == input . Count
64- && ( enableInversions ||
64+ && ( withInversions ||
6565 ( prefix . Count > 0 && prefix [ 0 ] . CompareTo ( prefix [ prefix . Count - 1 ] ) < 0 ) ) )
6666 {
6767 result . Add ( new List < T > ( prefix ) ) ;
@@ -75,15 +75,15 @@ private static void Recurse<T>(List<T> input,
7575
7676 for ( int j = 0 ; j < input . Count ; j ++ )
7777 {
78- if ( prefixIndices . Contains ( j ) && ! enableRepetition )
78+ if ( prefixIndices . Contains ( j ) && ! withRepetition )
7979 {
8080 continue ;
8181 }
8282
8383 prefix . Add ( input [ j ] ) ;
8484 prefixIndices . Add ( j ) ;
8585
86- Recurse ( input , enableRepetition , enableInversions , prefix , prefixIndices , result ) ;
86+ Recurse ( input , withRepetition , withInversions , prefix , prefixIndices , result ) ;
8787
8888 prefix . RemoveAt ( prefix . Count - 1 ) ;
8989 prefixIndices . Remove ( j ) ;
0 commit comments