public static long Problem45() { /* * Triangle, pentagonal, and hexagonal numbers are generated by the following formulae: * * Triangle Tn=n(n+1)/2 1, 3, 6, 10, 15, ... * Pentagonal Pn=n(3n−1)/2 1, 5, 12, 22, 35, ... * Hexagonal Hn=n(2n−1) 1, 6, 15, 28, 45, ... * It can be verified that T285 = P165 = H143 = 40755. * * Find the next triangle number that is also pentagonal and hexagonal. */ long n = 286L; long l = 0L; do { l = (n * (n + 1)) / 2; n = n + 1; } while (!Formulas.isTriangular(l) || !Formulas.isPentagonal(l) || !Formulas.isHexagonal(l)); return(l); }
public static long Problem42() { long result = 0; string text = System.IO.File.ReadAllText(@"res\p042_words.txt"); foreach (string word in text.Split(',')) { string w = word.Replace("\"", ""); long val = 0; foreach (char c in w) { val += c - 64; } if (Formulas.isTriangular(val)) { result++; } } return(result); }