public static int PentagonNumbers(int n) { int min = int.MaxValue; List <long> pentagons = SpecialSequences.pentagonalnumbers(n); HashSet <long> hashpent = new HashSet <long>(pentagons); foreach (int k in pentagons) { foreach (int j in pentagons) { int tempsum = k + j; if (!hashpent.Contains(tempsum)) { continue; } int tempmin = k - j; if (!hashpent.Contains(tempmin)) { continue; } if (tempmin < min) { min = tempmin; } } } return(min); }
public static long LongestCollatzSequence(int n) { SpecialSequences.generatecollatz(n); int max = SpecialSequences.CollatzSequences.Values.Max(); return(SpecialSequences.CollatzSequences.FirstOrDefault(x => x.Value == max).Key); }
public static int HighlyDivisibleTriangularNumber(int n) { List <long> triangles = SpecialSequences.triangularnumbers(n * n); foreach (int triangle in triangles) { if (MiscFunctions.Divisors(triangle).Count() > n) { return(triangle); } } return(0); }
public static long TriangularPentagonalHexagonal(int n) { List <long> pentagon = SpecialSequences.pentagonalnumbers(n); List <long> hexagon = SpecialSequences.hexagonalnumbers(n); HashSet <long> penthash = new HashSet <long>(pentagon); for (int i = 143; i < hexagon.Count; i++) { if (penthash.Contains(hexagon[i])) { return(hexagon[i]); } } return(0); }
public static int IntegerRightTriangles(int n) { List <List <int> > righttriangles = SpecialSequences.GenerateTriangles(n); List <int> perimeters = new List <int>(); foreach (List <int> triangle in righttriangles) { if (triangle.Sum() <= 1000) { perimeters.Add(triangle.Sum()); } } var most = perimeters.GroupBy(i => i).OrderByDescending(grp => grp.Count()) .Select(grp => grp.Key).First(); return(most); }
public static int OddComposite() { int comp = 0; List <int> primes = PrimeFunctions.GeneratePrimes(10000); HashSet <int> primeshash = MiscFunctions.ListToHash(primes); List <int> squares = SpecialSequences.squares(1000); HashSet <int> squareshash = MiscFunctions.ListToHash(squares); int i = 3; bool found = false; while (comp == 0) { found = false; i += 2; if (primeshash.Contains(i)) { continue; } for (int j = 0; j < primes.Count; j++) { if (primes[j] > i) { break; } for (int k = 0; k < squares.Count; k++) { if (squares[k] * 2 > i) { break; } if (primes[j] + (squares[k] * 2) == i) { found = true; } } } if (!found) { comp = i; } } return(comp); }
public static int CodedTriangleNumbers(string n) { int count = 0; string str = FileFunctions.readfileintostring("Problem42"); str = str.Replace("/", ""); str = str.Replace("\"", ""); string[] arr = str.Split(','); List <long> triangles = SpecialSequences.triangularnumbers(1000); foreach (string word in arr) { if (triangles.Contains(MiscFunctions.UppercaseWordValue(word))) { count++; } } return(count); }
public static int NumberSpiralDiagonals(int n) { return(SpecialSequences.SpiralNumbers((n + 1) / 2).Sum()); }
public static int fibbonacciNumber(int n) { SpecialSequences.GenerateFibbonacciDigits(n); return(SpecialSequences.fibbonaccisequence.Count + 1); }