public static int MaximumPathSum1(string n) { string[] temp = FileFunctions.readfileintostringarr(n); int[][] tri = FileFunctions.stringtointarraySplit2d(temp, ' '); for (int j = tri.GetLength(0) - 2; j >= 0; j--) { for (int i = 0; i < tri[j].Length; i++) { tri[j][i] += Math.Max(tri[j + 1][i], tri[j + 1][i + 1]); } } return(tri[0][0]); }
public static long SubstringDivisibility() { long sum = 0; var perm = SomeExtensions.GetPermutations(nums); List <List <int> > list = FileFunctions.ienumtolist(perm); foreach (List <int> num in list) { if (SubStringTest(num)) { sum += MiscFunctions.ListToLong(num); } } return(sum); }
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 long NamesScores(string n) { long sum = 0; string names = FileFunctions.readfileintostring(n); string[] namessplit = names.Split(','); Array.Sort(namessplit, StringComparer.InvariantCulture); for (int i = 0; i < namessplit.Length; i++) { int tempsum = 0; for (int j = 1; j < namessplit[i].Length - 1; j++) { string m = namessplit[i]; char k = m[j]; tempsum += namessplit[i][j] - 64; } sum += (tempsum * (i + 1)); } return(sum); }
public static long LargestProductInASeries(string n, int m) { long maxmult = 1; long mult = 1; string file = FileFunctions.readfileintostring("Problem8"); int[] filenums = FileFunctions.stringtointarray(file); for (int i = 0; i < filenums.Length - m; i++) { mult = 1; for (int j = i; j < i + m; j++) { mult *= filenums[j]; } if (mult > maxmult) { maxmult = mult; } } return(maxmult); }
public static int LargestProductInAGrid(string n, int m) { int mult = 1; string[] strnums = FileFunctions.readfileintostringarr(n); int[][] nums = FileFunctions.stringtointarraySplit2d(strnums, ' '); for (int i = 0; i < nums.Count(); i++) { for (int j = 0; j < nums[0].Count(); j++) { if (i < nums.Count() - m) { int tempmult = 1; for (int k = 0; k < m; k++) { tempmult *= nums[i + k][j]; } if (tempmult > mult) { mult = tempmult; } } if (j < nums.Count() - m) { int tempmult = 1; for (int k = 0; k < m; k++) { tempmult *= nums[i][j + k]; } if (tempmult > mult) { mult = tempmult; } } if (j < nums.Count() - m && i < nums.Count() - m) { int tempmult = 1; for (int k = 0; k < m; k++) { tempmult *= nums[i + k][j + k]; } if (tempmult > mult) { mult = tempmult; } } if (j > m && i < nums.Count() - m) { int tempmult = 1; for (int k = 0; k < m; k++) { tempmult *= nums[i + k][j - k]; } if (tempmult > mult) { mult = tempmult; } } } } return(mult); }
public static int SumOfDigits(BigInteger n) { int[] nums = FileFunctions.stringtointarray(n.ToString()); return(nums.Sum()); }
public static int[] DigitsFromInt(int n) { return(FileFunctions.stringtointarray(n.ToString())); }