public static bool IsPerfectNumber(this int value) { var isPerfect = false; var properDivisors = CustomRange.Int32(1, Convert.ToInt32(Math.Sqrt(value))).Where(d => (value % d == 0)); int divisorsSum = properDivisors.Sum(); if (divisorsSum.IsPrime()) { int lastDivisor = properDivisors.Last(); isPerfect = (value == (lastDivisor * divisorsSum)); } return(isPerfect); }
public static IEnumerable <float> Single(float from, float to) { return(CustomRange.Single(from, to, 1.0f)); }
public static IEnumerable <ulong> UInt64(ulong from, ulong to) { return(CustomRange.UInt64(from, to, 1UL)); }
public static IEnumerable <long> Int64(long from, long to) { return(CustomRange.Int64(from, to, 1L)); }
public static IEnumerable <uint> UInt32(uint from, uint to) { return(CustomRange.UInt32(from, to, 1U)); }
public static IEnumerable <int> Int32(int from, int to) { return(CustomRange.Int32(from, to, 1)); }
public static long ToPowerOf(this long @base, int exponent) => CustomRange.Int64(1L, exponent).Select(_L => @base).Product();
public static IEnumerable <DateTime> DateTime(DateTime from, DateTime to) { return(CustomRange.DateTime(from, to, 1.0)); }
public static IEnumerable <char> Char(char from, char to) { return(CustomRange.Char(from, to, 1)); }
public static IEnumerable <byte> Byte(byte from, byte to) { return(CustomRange.Byte(from, to, 1)); }
public static IEnumerable <sbyte> SByte(sbyte from, sbyte to) { return(CustomRange.SByte(from, to, 1)); }
public static IEnumerable <char> Char(char from, char to, int step) { return(CustomRange.Int32(from, to, step).Select(i => (char)i)); }
public static IEnumerable <byte> Byte(byte from, byte to, int step) { return(CustomRange.Int32(from, to, step).Select(i => (byte)i)); }
public static IEnumerable <long> Divisors(this long n) => CustomRange.Int64(1L, n).Where(iL => n % iL == 0);
public static IEnumerable <double> Double(double from, double to) { return(CustomRange.Double(from, to, 1.0)); }
public static IEnumerable <short> Int16(short from, short to) { return(CustomRange.Int16(from, to, 1)); }
public static IEnumerable <decimal> Decimal(decimal from, decimal to) { return(CustomRange.Decimal(from, to, 1.0m)); }
public static IEnumerable <ushort> UInt16(ushort from, ushort to) { return(CustomRange.UInt16(from, to, 1)); }
public static IEnumerable <ushort> UInt16(ushort from, ushort to, int step) { return(CustomRange.Int32(from, to, step).Select(i => (ushort)i)); }
public static int ToPowerOf(this int @base, int exponent) => CustomRange.Int32(1, exponent).Select(_ => @base).Product();