-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d6bba4f
commit c9c8f78
Showing
5 changed files
with
194 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
namespace DigitalCathedral; | ||
|
||
public static class CombinatoricsExtensions | ||
{ | ||
|
||
public static IEnumerable<IEnumerable<T>> GetCombinations<T>( | ||
this IEnumerable<T> values, | ||
int k, | ||
IEqualityComparer<T> equalityComparer) | ||
{ | ||
ThrowIfNotDistinctElements(values, equalityComparer); | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public static IEnumerable<IEnumerable<T>> GetUniqueCombinations<T>( | ||
this IEnumerable<T> values, | ||
int k, | ||
IEqualityComparer<T> equalityComparer) | ||
{ | ||
ThrowIfNotDistinctElements(values, equalityComparer); | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public static IEnumerable<IEnumerable<T>> GetSetOfAllSubsets<T>( | ||
this IEnumerable<T> values, | ||
IEqualityComparer<T> equalityComparer) | ||
{ | ||
ThrowIfNotDistinctElements(values, equalityComparer); | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public static IEnumerable<IEnumerable<T>> GetAllPermutations<T>( | ||
this IEnumerable<T> values, | ||
IEqualityComparer<T> equalityComparer) | ||
{ | ||
ThrowIfNotDistinctElements(values, equalityComparer); | ||
throw new NotImplementedException(); | ||
} | ||
|
||
private static void ThrowIfNotDistinctElements<T>( | ||
IEnumerable<T> values, | ||
IEqualityComparer<T> equalityComparer) | ||
{ | ||
var distinctValues = values.Distinct(equalityComparer).ToArray(); | ||
if (distinctValues.Length != values.Count()) | ||
{ | ||
throw new ArgumentException("Found equal elements in collection.", nameof(values)); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace DigitalCathedral; | ||
|
||
public sealed class IntEqualityComparer : IEqualityComparer<int> | ||
{ | ||
private const int EventIntHashCode = 0; | ||
|
||
public bool Equals( | ||
int x, | ||
int y) | ||
{ | ||
if (x % 2 == 0 && y % 2 == 0) | ||
{ | ||
return true; | ||
} | ||
|
||
return x.Equals(y); | ||
} | ||
|
||
public int GetHashCode( | ||
int obj) | ||
{ | ||
if (obj % 2 == 0) | ||
{ | ||
return EventIntHashCode; | ||
} | ||
return obj.GetHashCode(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters