public void CalculateRadius() { int indexOfLastLivingShip = 1; for (int i = myFleet.ships.Count - 1; i >= 0; --i) { if (myFleet.ships[i] != null) { indexOfLastLivingShip = i; break; } } Vector3 midpoint = Vector3.zero; midpoint.z = ShipTargetPositionLocator.GetShipTargetPosition(indexOfLastLivingShip).z * 0.75f; transform.localPosition = midpoint; int lastRow = TriangleNumbers.GetRowInTriangle(indexOfLastLivingShip); // ******************************************************************************** // DON'T DELETE - TOOK AGES TO FIGURE OUT ***************************************** // ******************************************************************************** //int lastRowStart = TriangleNumbers.GetTriangleNumber(lastRow - 1) + 1; //int lastRowCount = TriangleNumbers.GetCountInRow(lastRow); //Vector3 leftMost = ShipTargetPositionLocator.GetShipTargetPosition(lastRowStart); //Vector3 rightMost = ShipTargetPositionLocator.GetShipTargetPosition(lastRowStart + lastRowCount -1); //float lastRowWidth = Vector3.Distance(leftMost, rightMost); trigger.radius = ShipTargetPositionLocator.GAPSIZE * (lastRow + 1) * 0.5f; //Debug.Log($"Detection Sphere radius is now: {trigger.radius}"); }
public void Run() { TriangleNumbers num = new TriangleNumbers(40); Factorial fac = new Factorial(40); Console.WriteLine("Tringle Numbers"); MathRrcuration(num); Console.WriteLine("Factorials"); MathRrcuration(fac); //Console.WriteLine("Anagramm"); //Anagramm("cat"); //Anagramm("Мария"); Console.WriteLine("Recuraction Search"); RecurectionBinarySearch search = new RecurectionBinarySearch(); search.MathWithRec(750); search.MathWithoutRec(750); Console.WriteLine(search.ResultNotRec); Console.WriteLine(search.ResultRec); Console.WriteLine(search.OtherSearch(950)); HanoyTowerRecur tower = new HanoyTowerRecur(4, false); }
public override uint Run() { // The sequence of triangle numbers is generated by adding the natural numbers.So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28.The first ten terms would be: // 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ... // Let us list the factors of the first seven triangle numbers: // 1: 1 // 3: 1,3 // 6: 1,2,3,6 // 10: 1,2,5,10 // 15: 1,3,5,15 // 21: 1,3,7,21 // 28: 1,2,4,7,14,28 // We can see that 28 is the first triangle number to have over five divisors. // What is the value of the first triangle number to have over five hundred divisors? foreach (var triangleNumber in TriangleNumbers.GetTriangleNumbers(uint.MaxValue)) { var numberOfFactors = Number.GetDivisors(triangleNumber, false).Count(); if (numberOfFactors > 500) { return(triangleNumber); } } return(0); }
/// <summary> /// Gets the target position of the ship at the provided <paramref name="index"/> /// </summary> /// <param name="index">The index of the ship in the fleet</param> /// <returns>The target position of the ship</returns> public static Vector3 GetShipTargetPosition(int index) { System.Tuple <int, int> rowAndPos = TriangleNumbers.GetRowAndPos(index); int row = rowAndPos.Item1; int posInRow = rowAndPos.Item2; //Debug.Log($"Ship #{index} is in row {row} at position {posInRow}"); return(GetShipTargetPosition(row, posInRow)); }
static void Main() { Fibbonacci fi = new Fibbonacci(); var fib = fi.NextMemb(7).ToArray(); TriangleNumbers triangleNumbers = new TriangleNumbers(); var tr = triangleNumbers.NextMemb(7).ToArray(); Console.WriteLine("Fib"); Array.ForEach(fib, Console.WriteLine); Console.WriteLine("triangle"); Array.ForEach(tr, Console.WriteLine); Console.WriteLine("+"); for (int i = 0; i < Math.Max(tr.Count(), fib.Count()); i++) { Console.WriteLine(tr[i] + fib[i]); } }
static void Main(string[] args) { DateTime start = DateTime.Now; long lookingFor = 500; long found = 0; TriangleNumbers triangleNumbers = new TriangleNumbers(); foreach (long tn in triangleNumbers) { long divCount = CountDivisors(tn); //Console.WriteLine("NUM: " + tn + "," + divCount); if (divCount >= lookingFor) { found = tn; break; } } Console.WriteLine(found); Console.WriteLine("TIME: " +(DateTime.Now-start).Seconds + "sec"); Console.WriteLine("Press ENTER to Exit"); Console.ReadLine(); }
void SpawnRowsOfShips(int rows) => SpawnShips(TriangleNumbers.GetTriangleNumber(rows));
GameObject CreateShip(int index) => CreateShip(TriangleNumbers.GetRowAndPos(index + 1));
public static long MaximumSumToBase() { var triangleNumbers = new TriangleNumbers("Problem18.txt"); return(triangleNumbers.MaximumSum()); }
public long FindFirstNumberInSequenceWithMoreThanXFactors(int numFactors) { var sequence = new TriangleNumbers(); return sequence.Generate().First(x => factorer.FindNonTrivialFactors(x).Count() + 2 > numFactors); }
public static int Solve() { TriangleNumbers tnums = new TriangleNumbers(); tnums.Next(); while (Helper.DoMath.GetFactors(tnums.list[^ 1]) <= Seed)
public void Test1() { Assert.AreEqual(true, TriangleNumbers.isTriangleNumber(125250)); }
public void Test2() { Assert.AreEqual(true, TriangleNumbers.isTriangleNumber(3126250)); }