72 lines
1.7 KiB
C#
72 lines
1.7 KiB
C#
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
|
||
|
namespace BITKit
|
||
|
{
|
||
|
public static class MathE
|
||
|
{
|
||
|
public static bool Equals<T>(params T[] objs)
|
||
|
{
|
||
|
var a = objs.FirstOrDefault();
|
||
|
foreach (var b in objs)
|
||
|
{
|
||
|
if (a.Equals(b))
|
||
|
{
|
||
|
a = b;
|
||
|
continue;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
public static IEnumerable<T> Subtract<T>(IEnumerable<T> a, IEnumerable<T> b) where T : IEnumerable
|
||
|
{
|
||
|
List<T> list = new();
|
||
|
foreach (var x in a)
|
||
|
{
|
||
|
if (b.Contains(x))
|
||
|
{
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
list.Add(x);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return list;
|
||
|
}
|
||
|
|
||
|
public static bool Contains<T>(IEnumerable<T> a, IEnumerable<T> b)
|
||
|
{
|
||
|
foreach (var x in b)
|
||
|
{
|
||
|
if (a.Contains(x))
|
||
|
{
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
public static IEnumerable<T[]> Combinations<T>(IEnumerable<T> source)
|
||
|
{
|
||
|
if (null == source) throw new ArgumentNullException(nameof(source));
|
||
|
T[] data = source.ToArray();
|
||
|
return Enumerable.Range(0, 1 << (data.Length) - 1)
|
||
|
.Select(index => data.Where((v, i) => (index & (1 << i)) != 0).ToArray());
|
||
|
}
|
||
|
}
|
||
|
}
|