Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,22 @@
using System;
class Program
{
static int Factorial(int number)
{
if(number < 0)
throw new ArgumentOutOfRangeException(nameof(number), number, "Must be zero or a positive number.");
var accumulator = 1;
for (var factor = 1; factor <= number; factor++)
{
accumulator *= factor;
}
return accumulator;
}
static void Main()
{
Console.WriteLine(Factorial(10));
}
}

View file

@ -0,0 +1,17 @@
using System;
class Program
{
static int Factorial(int number)
{
if(number < 0)
throw new ArgumentOutOfRangeException(nameof(number), number, "Must be zero or a positive number.");
return number == 0 ? 1 : number * Factorial(number - 1);
}
static void Main()
{
Console.WriteLine(Factorial(10));
}
}

View file

@ -0,0 +1,27 @@
using System;
class Program
{
static int Factorial(int number)
{
if(number < 0)
throw new ArgumentOutOfRangeException(nameof(number), number, "Must be zero or a positive number.");
return Factorial(number, 1);
}
static int Factorial(int number, int accumulator)
{
if(number < 0)
throw new ArgumentOutOfRangeException(nameof(number), number, "Must be zero or a positive number.");
if(accumulator < 1)
throw new ArgumentOutOfRangeException(nameof(accumulator), accumulator, "Must be a positive number.");
return number == 0 ? accumulator : Factorial(number - 1, number * accumulator);
}
static void Main()
{
Console.WriteLine(Factorial(10));
}
}

View file

@ -0,0 +1,15 @@
using System;
using System.Linq;
class Program
{
static int Factorial(int number)
{
return Enumerable.Range(1, number).Aggregate((accumulator, factor) => accumulator * factor);
}
static void Main()
{
Console.WriteLine(Factorial(10));
}
}

View file

@ -0,0 +1,31 @@
using System;
using System.Numerics;
using System.Linq;
class Program
{
static BigInteger factorial(int n) // iterative
{
BigInteger acc = 1; for (int i = 1; i <= n; i++) acc *= i; return acc;
}
static public BigInteger Factorial(int number) // functional
{
return Enumerable.Range(1, number).Aggregate(new BigInteger(1), (acc, num) => acc * num);
}
static public BI FactorialQ(int number) // functional quick, uses prodtree method
{
var s = Enumerable.Range(1, number).Select(num => new BI(num)).ToArray();
int top = s.Length, nt, i, j;
while (top > 1) {
for (i = 0, j = top, nt = top >> 1; i < nt; i++) s[i] *= s[--j];
top = nt + ((top & 1) == 1 ? 1 : 0);
}
return s[0];
}
static void Main(string[] args)
{
Console.WriteLine(Factorial(250));
}
}