View Vector<T>.cs
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
/// <summary> | |
/// A generic Vector class. | |
/// Uses/Requires the GenericArithmeticFactory class: | |
/// https://gist.github.com/AdamWhiteHat/71d548ebfb2ee67fcbd78a39a9751423 | |
/// </summary> | |
public class Vector<T> | |
{ | |
/// <summary>The dimension of the vector, i.e. the number of elements or its length.</summary> | |
public int Dimensions { get { return Elements == null ? 0 : Elements.Length; } } |
View SandPile.cs
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
/// <summary>Abelian Sandpile Class</summary> | |
public class SandPile : IEquatable<SandPile> | |
{ | |
#region static Sandpile Values | |
public static SandPile Zero = new SandPile(new int[,] { { 2, 1, 2 }, { 1, 0, 1 }, { 2, 1, 2 } }, 4); | |
public static SandPile One = new SandPile(new int[,] { { 3, 2, 3 }, { 2, 1, 2 }, { 3, 2, 3 } }, 4); | |
public static SandPile NegativeOne = new SandPile(new int[,] { { 1, 3, 1 }, { 3, 3, 3 }, { 1, 3, 1 } }, 4); | |
// These can all be constructed from the above three sandpiles. |
View BestStringEqualityComparer.cs
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
/// <summary> | |
/// A IEqualityComparer<string> that provides the mathematically best GetHashCode | |
/// possible for adding millions of strings to Dictionaries, HashTables, HashMaps and more. | |
/// It works by interpreting an array of bytes (your string) as a number in base 256, | |
/// and then returning the unit of that number in the multiplicative group of integers modulo a prime p, | |
/// where p is the largest prime less than 2^32. | |
/// </summary> | |
public class BestStringEqualityComparer : IEqualityComparer<string> | |
{ | |
public int GetHashCode(string obj) |
View INotifyPropertyChangedEx.cs
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
namespace ComponentModelEx | |
{ | |
public delegate void PropertyChangedExEventHandler(object sender, PropertyChangedExEventArgs e); | |
public interface INotifyPropertyChangedEx | |
{ | |
event PropertyChangedExEventHandler PropertyChangedEx; | |
} | |
} |
View DictionaryChangedEventArgs.cs
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
using System; | |
using System.Collections.Generic; | |
namespace ComponentModelEx | |
{ | |
public class DictionaryChangedEventArgs<TKey, TValue> : EventArgs | |
{ | |
public DictionaryChangedAction Action => _action; | |
public KeyValuePair<TKey, TValue> OldValue => _oldValue; | |
public KeyValuePair<TKey, TValue> NewValue => _newValue; |
View IsValidIPv6Address.cs
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
public static bool IPv6Check(string input) | |
{ | |
if (string.IsNullOrWhiteSpace(input)) | |
{ | |
return false; | |
} | |
if (input.IndexOf("::") != input.LastIndexOf("::")) // 'The "::" can only appear once in an address.' | |
{ | |
return false; |
View GenericArithmeticFactory.cs
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
public static class GenericArithmeticFactory<T> | |
{ | |
private static Dictionary<ExpressionType, Func<T, T, T>> _binaryOperationDictionary; | |
private static Dictionary<ExpressionType, Func<T, T, bool>> _comparisonOperationDictionary; | |
private static Func<T, T> _sqrtOperation = null; | |
static GenericArithmeticFactory() | |
{ | |
_binaryOperationDictionary = new Dictionary<ExpressionType, Func<T, T, T>>(); | |
_comparisonOperationDictionary = new Dictionary<ExpressionType, Func<T, T, bool>>(); |
View PasswordHashing.cs
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
/// <summary> | |
/// Requires the BCrypt nuget package. Available here: https://www.nuget.org/packages/BCrypt.Net-Next | |
/// </summary> | |
public static class PasswordHashing | |
{ | |
public static string HashPassword(string password, int workFactor) | |
{ | |
return BCrypt.Net.BCrypt.HashPassword(password, workFactor); | |
} |
View FastFactorial.cs
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
public static class FastFactorial | |
{ | |
public static BigInteger Factorial(BigInteger n) | |
{ | |
return MultiplyRange(2, n); | |
} | |
private static BigInteger MultiplyRange(BigInteger from, BigInteger to) | |
{ | |
var diff = to - from; |
View NumberTheory.Maths.cs
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
using System; | |
using System.Linq; | |
using System.Numerics; | |
using System.Collections.Generic; | |
public static class Maths | |
{ | |
/// <summary> | |
/// Legendre Symbol returns 1 for a (nonzero) quadratic residue mod p, -1 for a non-quadratic residue (non-residue), or 0 on zero. | |
/// </summary> |
NewerOlder