Skip to content

Instantly share code, notes, and snippets.

View AdamWhiteHat's full-sized avatar
🏠
Working from home

Adam White AdamWhiteHat

🏠
Working from home
View GitHub Profile
@AdamWhiteHat
AdamWhiteHat / Factorization.cs
Last active May 22, 2022 17:51
Prime Factorization class.
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()
@AdamWhiteHat
AdamWhiteHat / NumberTheory.Maths.cs
Last active June 19, 2022 02:38
Number Theory functions: Legendre Symbol, Eulers Criterion, Tonelli-Shanks, Chinese Remainder Theorem, Modular Multiplicative Inverse, Primitive Root, Multiplicative Order, Discrete Logarithm, Discrete Root, Eulers Totient Phi, Carmichael Lambda, Exponentiation by Squaring, Factorial, Complex Gamma Function, Nth Root, Prime Factorization, LCM, GCD.
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>
@AdamWhiteHat
AdamWhiteHat / GenericArithmeticFactory.cs
Last active January 25, 2023 17:56
Generic arithmetic operations with an example
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>>();
@AdamWhiteHat
AdamWhiteHat / ObservableDictionary.cs
Last active September 14, 2023 23:50
ObservableDictionary - Like an ObservableCollection, but its a Dictionary. Fires events for: Add, Remove, Replace, and Clear.
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;