public void CycleLenthHasCycle() { var expected = 115; var actual = MathLibrary.CycleLength(1, 452); Assert.Equal(expected, actual); }
public void CycloidTest() { MathLibrary ml = new MathLibrary(); TestScaffold.TestLines( lines: new List <string>() { "import basic:math l:math;0.0", "l:math.f:cycloid(-1.0, 0.75)", "l:math.f:cycloid(-1.0, 5.0)", "l:math.f:cycloid(7.0, 3.0)", "l:math.f:cycloid(10, 15)", "v:test := 15; v:a := 3; l:math.f:cycloid(v:test, v:a)", }, expected: new List <object>() { 0.0, ml.Cycloid(-1.0, 0.75), ml.Cycloid(-1.0, 5.0), ml.Cycloid(7.0, 3.0), ml.Cycloid(10.0, 15.0), ml.Cycloid(15.0, 3.0) } ); }
public string Compute() { List <long> primes = MathLibrary.GetPrime(1000000); // retrieve the list of prime numbers List <long> circularPrimes = new List <long>(); char[] anyOf = { '0', '2', '4', '5', '6', '8' }; bool isPrime; foreach (long primeNumber in primes) // check each prime number { string stringDigits = primeNumber.ToString(); isPrime = true; if (stringDigits.IndexOfAny(anyOf) >= 0 & stringDigits.Length > 1) // rule out a number with even digits or a 5 { isPrime = false; continue; } for (int index = 0; index < stringDigits.Length; index++) // run through each circular premutation { string circularDigits = stringDigits.Substring(index) + stringDigits.Substring(0, index); if (!primes.Contains(long.Parse(circularDigits))) // if a number is not prime then stop checking { isPrime = false; break; } } if (isPrime) { circularPrimes.Add(primeNumber); } } return(circularPrimes.Count.ToString()); }
public string Compute() { long result = 0; long count = 0; List <long> triangleNumbers = MathLibrary.GetTriangle(100000); List <long> pentagonNumbers = MathLibrary.GetPentagon(100000); List <long> hexagonNumbers = MathLibrary.GetHexagon(100000); foreach (long number in triangleNumbers) { count++; if (count <= 285) { continue; } if (!pentagonNumbers.Contains(number)) { continue; } if (!hexagonNumbers.Contains(number)) { continue; } result = number; break; } return(result.ToString()); }
private float Operation(Flow flow) { float normalizedInput = MathLibrary.ReverseLinearFunction(flow.GetValue <float>(input), flow.GetValue <float>(minimumRange), flow.GetValue <float>(maximumRange)); float normalizedInflection = MathLibrary.ReverseLinearFunction(flow.GetValue <float>(inflectionPoint), flow.GetValue <float>(minimumRange), flow.GetValue <float>(maximumRange)); return(MathLibrary.DecayingSigmoid(normalizedInput, normalizedInflection, flow.GetValue <float>(minimum), flow.GetValue <float>(decayFactor), flow.GetValue <float>(scale))); }
public void ReversingEvenDigits() { long expected = 4321; long actual = MathLibrary.ReverseDigits(1234); Assert.AreEqual(expected, actual, "Reversed even number of digits failed."); }
private float Operation(Flow flow) { return(MathLibrary.LinearFunctionOfRange( flow.GetValue <float>(input), flow.GetValue <float>(minInputRange), flow.GetValue <float>(maxInputRange), flow.GetValue <float>(minimum), flow.GetValue <float>(maximum))); }
public static void MakingTriangle() { var N = IOLibrary.ReadInt(); var L = IOLibrary.ReadIntArray(); var sortedL = L.Sort(); if (N < 3) { Console.WriteLine(0); return; } var count = 0; foreach (var combinationIndex in MathLibrary.GetCombinationIndexCollection(N, 3)) { var i = combinationIndex[0]; var j = combinationIndex[1]; var k = combinationIndex[2]; if (sortedL[i] != sortedL[j] && sortedL[j] != sortedL[k] && sortedL[i] + sortedL[j] > sortedL[k]) { count++; } } Console.WriteLine(count); }
public string Compute() { long result = 999999999; List <long> pentagonList = MathLibrary.GetPentagon(5000); long[] pentagonArray = pentagonList.ToArray(); for (long pj = 0; pj < pentagonArray.Length - 1; pj++) { for (long pk = pj + 1; pk < pentagonArray.Length; pk++) { if (!pentagonList.Contains(pentagonArray[pj] + pentagonArray[pk])) { continue; } if (!pentagonList.Contains(pentagonArray[pk] - pentagonArray[pj])) { continue; } long difference = pentagonArray[pk] - pentagonArray[pj]; if (difference < result) { result = difference; } } } return(result.ToString()); }
static void Main(string[] args) { MathLibrary mathLib = new MathLibrary(); Console.WriteLine(mathLib.Add(1, 2)); Console.ReadKey(); }
/// <summary> /// When on a platform, adjust character's position and velocity to mantain the platform. /// </summary> /// <param name="probingPosition">A probing position, this can be different from character's current position.</param> /// <param name="probingRotation">A probing rotation, this can be different from character's current position.</param> private void SnapToPlatform(ref Vector3 probingPosition, ref Quaternion probingRotation) { // Compute distance to platform GroundHit hitInfo; if (!ComputeGroundHit(probingPosition, probingRotation, out hitInfo, groundDetection.castDistance)) { return; } // If not on a platform, return var otherRigidbody = hitInfo.groundRigidbody; if (otherRigidbody == null || !otherRigidbody.isKinematic) { return; } // On a platform... // Compute target grounded position var up = probingRotation * Vector3.up; var groundedPosition = probingPosition - up * hitInfo.groundDistance; // Update character's velocity and snap to platform var pointVelocity = otherRigidbody.GetPointVelocity(groundedPosition); _rigidbody.velocity = velocity + pointVelocity; var deltaVelocity = pointVelocity - platformVelocity; groundedPosition += deltaVelocity.onlyXZ() * Time.fixedDeltaTime; // On ledge 'solid' side, compute a flattened snap point if (isOnLedgeSolidSide) { groundedPosition = MathLibrary.ProjectPointOnPlane(groundedPosition, hitInfo.groundPoint, up); } // Update character's position probingPosition = groundedPosition; // On rotating platform, update character's rotation if (otherRigidbody.angularVelocity == Vector3.zero) { return; } var yaw = Vector3.Project(otherRigidbody.angularVelocity, up); var yawRotation = Quaternion.Euler(yaw * Mathf.Rad2Deg * Time.deltaTime); probingRotation *= yawRotation; }
private float Operation(Recursion recursion) { float normalizedInput = MathLibrary.ReverseLinearFunction(input.GetValue <float>(), minimumRange.GetValue <float>(), maximumRange.GetValue <float>()); float normalizedInflection = MathLibrary.ReverseLinearFunction(inflectionPoint.GetValue <float>(), minimumRange.GetValue <float>(), maximumRange.GetValue <float>()); return(MathLibrary.DecayingSigmoid(normalizedInput, normalizedInflection, minimum.GetValue <float>(), decayFactor.GetValue <float>(), scale.GetValue <float>())); }
public void MaximumSubsetSum() { var expected = 9; var actual = MathLibrary.MaximumSubsetSum(new long[] { 1, 4, -6, 2, 3, 4, -3, -4, 6 }); Assert.Equal(expected, actual); }
public void CycleLenthNoCycle() { var expected = 0; var actual = MathLibrary.CycleLength(12, 3); Assert.Equal(expected, actual); }
public static void Collinearity() { var N = IOLibrary.ReadInt(); var pArray = new Point[N]; for (var i = 0; i < N; i++) { var(x, y) = IOLibrary.ReadInt2(); var p = new Point(x, y); pArray[i] = p; } foreach (var indexArray in MathLibrary.GetCombinationIndexCollection(N, 3)) { var p0 = pArray[indexArray[0]]; var p1 = pArray[indexArray[1]]; var p2 = pArray[indexArray[2]]; var area = Point.CalcTriangleArea(p0 - p1, p0 - p2); if (area == 0) { Console.WriteLine(IOLibrary.YesOrNo(true)); return; } } Console.WriteLine(IOLibrary.YesOrNo(false)); }
public static void GoodDistance() { var(N, D) = IOLibrary.ReadInt2(); var X = IOLibrary.ReadInt2DArray(N, D); var count = 0L; foreach (var pair in MathLibrary.GetCombinationIndexCollection(N, 2)) { var i = pair[0]; var j = pair[1]; var squareLength = 0L; for (var index = 0; index < D; index++) { var dx = X[i, index] - X[j, index]; squareLength += dx * dx; } var length = (int)Math.Sqrt(squareLength); if (length * length == squareLength) { count++; } } Console.WriteLine(count); }
public static void Creampuff() { var N = IOLibrary.ReadLong(); var list = MathLibrary.GetDivisorSortedList(N); IOLibrary.OutputList(list); }
/// <summary> /// 約数を列挙 /// </summary> /// <param name="n"></param> /// <returns></returns> public static IList <long> GetDivisorSortedList(long n) { var list = new List <long>(MathLibrary.GetDivisorList(n)); list.Sort(); return(list); }
public void ReversingOddDigits() { long expected = 987654321; long actual = MathLibrary.ReverseDigits(123456789); Assert.AreEqual(expected, actual, "Reversed odd number of digits failed."); }
/// <summary> /// A permutation is an ordered arrangement of objects. For example, 3124 is one possible permutation of the digits 1, 2, 3 and 4. /// If all of the permutations are listed numerically or alphabetically, we call it lexicographic order. /// The lexicographic permutations of 0, 1 and 2 are: /// 012 021 102 120 201 210 /// What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9? /// </summary> /// <returns>Zero</returns> public string Compute() { string result = null; string startingSequence = "0123456789"; long max = 10; long numberToFind = 1000000; for (long digit = 0; digit < max - 1; digit++) { long factorial = MathLibrary.Factorial(max - digit - 1); long position = numberToFind / factorial; long remainder = numberToFind % factorial; if (remainder > 0) { position++; } result = result + startingSequence.Substring((int)position - 1, 1); startingSequence = startingSequence.Remove((int)position - 1, 1); long factorialBorder = (position - 1) * factorial; numberToFind = numberToFind - factorialBorder; } return(result + startingSequence); }
public string Compute() { long result = 0; long max = 10000; List <long> primeNumbers = MathLibrary.GetPrime(max); List <long> doubleSquares = GetDoubleSquares(max); for (long number = 15; number <= max; number += 2) { if (primeNumbers.Contains(number)) { continue; } bool notConjecture = true; foreach (long primeNumber in primeNumbers) { if (primeNumber > number) { break; } if (doubleSquares.Contains(number - primeNumber)) { notConjecture = false; break; } } if (notConjecture) { result = number; break; } } return(result.ToString()); }
public string Compute() { long result = 0; long limit = 1000000; List <long> primeNumbers = MathLibrary.GetPrime(10000); long count = 10; // 10 is an arbitrary starting point. The starting point must be greater than 1 while (true) { if (count++ > limit) { break; } for (long index = 0; index < consecutive; index++) { long factors = MathLibrary.GetDistinctFactors(count + index, primeNumbers).Count; if (!factors.Equals(consecutive)) { break; } if (index.Equals(consecutive - 1)) { return(count.ToString()); } } } return(result.ToString()); }
public string Compute() { long result = 0; string digits = null; for (int digit = 1; digit <= 9; digit++) { digits += digit.ToString(); Premutations premutations = new Premutations(digits); for (int index = 1; index <= premutations.Count(); index++) { string premutation = premutations.GetPremutation(index); long candidate = long.Parse(premutation); if (candidate > result) { if (MathLibrary.IsPrime(candidate)) { result = candidate; } } } } return(result.ToString()); }
public string Compute() { long[] digitFactorials = new long[10]; long result = 0; for (int digit = 0; digit < 10; digit++) { digitFactorials[digit] = MathLibrary.Factorial(digit); } for (int number = 3; number < 50000; number++) { List <long> digits = MathLibrary.GetDigits(number); long factorialSum = 0; foreach (long digit in digits) { factorialSum += digitFactorials[digit]; } if (factorialSum == number) { result += number; } } return(result.ToString()); }
public void ClausenTest() { MathLibrary ml = new MathLibrary(); TestScaffold.TestLines( lines: new List <string>() { "import basic:math l:math;0.0", "l:math.f:clausen(-1.0)", "l:math.f:clausen(-1.0, 5.0)", "l:math.f:clausen(7.0, 3.0, 1.0)", "l:math.f:clausen(10, 15, 300)", "v:test := 15; v:a := 3; l:math.f:clausen(12.5, v:test, v:a)", }, expected: new List <object>() { 0.0, ml.Clausen(new double[] { -1.0 }), ml.Clausen(new double[] { -1.0, 5.0 }), ml.Clausen(new double[] { 7.0, 3.0, 1.0 }), ml.Clausen(new double[] { 10.0, 15.0, 300.0 }), ml.Clausen(new double[] { 12.5, 15.0, 3.0 }), } ); }
/// <summary> /// Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, /// begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value /// by its alphabetical position in the list to obtain a name score. /// /// For example, when the list is sorted into alphabetical order, COLIN, which is worth 3 + 15 + 12 + 9 + 14 = 53, is the /// 938th name in the list. So, COLIN would obtain a score of 938 × 53 = 49714. /// What is the total of all the name scores in the file? /// </summary> /// <returns></returns> public string Compute() { long result = 0; string text = System.IO.File.ReadAllText(@"C:\Users\Bill\Downloads\p022_names.txt").Replace('"', ' '); string[] names = text.Split(','); int count = 0; foreach (string name in names) { string trimmedName = name.TrimStart(' '); trimmedName = trimmedName.TrimEnd(' '); names[count++] = trimmedName; } Array.Sort(names); int order = 1; foreach (string name in names) { result += (MathLibrary.WordScore(name) * order++); } return(result.ToString()); }
private float Operation(Recursion recursion) { float inputValue = Mathf.Clamp01(input.GetValue <float>(recursion)); float inflectionPointValue = Mathf.Clamp01(inflectionPoint.GetValue <float>(recursion)); return(MathLibrary.DecayingSigmoid(inputValue, inflectionPointValue, minimum.GetValue <float>(), decayFactor.GetValue <float>(), scale.GetValue <float>())); }
public static void Travel() { var(N, K) = IOLibrary.ReadInt2(); var T = IOLibrary.ReadInt2DArray(N); var indexList = MathLibrary.GetPermutationIndex(Enumerable.Range(1, N - 1).ToArray()); var count = 0; foreach (var index in indexList) { var sumTime = 0; //末尾に終点0を追加 var newIndexList = index.Concat(new int[] { 0 }); var beforePoint = 0; foreach (var currentIndex in newIndexList) { var time = T[beforePoint][currentIndex]; sumTime += time; beforePoint = currentIndex; } if (sumTime == K) { count++; } } Console.WriteLine(count); }
/// <summary> /// Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n). /// If d(a) = b and d(b) = a, where a ≠ b, then a and b are an amicable pair and each of a and b are called amicable numbers. /// For example, the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110; therefore d(220) = 284. The proper divisors of 284 are 1, 2, 4, 71 and 142; so d(284) = 220. /// Evaluate the sum of all the amicable numbers under 10000. /// </summary> /// <returns></returns> public string Compute() { long result = 0; List <long> amicableNumbers = new List <long>(); long[] divisorSums = new long[10000]; for (long number = 1; number < 10000; number++) { divisorSums[number] = MathLibrary.SeriesSum(MathLibrary.GetDivisors(number)); } for (long number = 2; number < 10000; number++) { long sum = divisorSums[number]; if (sum < 10000) { if (sum != number) { if (divisorSums[sum].Equals(number)) { result += number; } } } } return(result.ToString());; }
public void FibonacciNumbers() { var expected = BigInteger.Parse("222232244629420445529739893461909967206666939096499764990979600"); var actual = MathLibrary.FibonacciNumbers().Skip(300).First(); Assert.Equal(expected, actual); }