Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.Collections; | |
using System.ComponentModel; | |
using System.Collections.Generic; | |
using System.Collections.Specialized; | |
using System.Collections.ObjectModel; | |
using System.Runtime.CompilerServices; | |
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> | |
/// Interval arithmetic type class | |
/// </summary> | |
public class Interval : IEquatable<Interval>, IComparable<Interval>, IComparable | |
{ | |
#region Properties | |
public static Interval Zero; | |
public static Interval One; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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; } } |
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>>(); |
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. |
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) |
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> |
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.Numerics; | |
public static class Factorization | |
{ | |
private static BigInteger _cacheCeiling; | |
private static List<BigInteger> _primeCache; | |
private static BigInteger _cacheLargestPrimeCurrently; | |
private static BigInteger[] _probablePrimeCheckBases; | |
static Factorization() |
NewerOlder