using System.Linq; using System.Text.RegularExpressions; namespace OEIS_Prime_Factors { public static class A3242xx { public static bool IsA324257(long n, long[] distinctFactors) { bool stat = true; string nStr = n.ToString(); bool[] digitUsed = new bool[nStr.Length]; foreach (long p in distinctFactors) { if (!nStr.Contains(p.ToString())) { // n doesn't contain this factor stat = false; break; } else { // all digits in n need to be used int index = -1; while ((index = nStr.IndexOf(p.ToString(), index + 1)) > -1) { for (int offset = 0; offset < p.ToString().Length; offset++) { digitUsed[index + offset] = true; } } } } foreach (bool b in digitUsed) { if (!b) { stat = false; break; } } return stat; } public static bool IsA324258(long n, long[] distinctFactors) { // subsequence of A324257 without overlap if (!IsA324257(n, distinctFactors)) return false; string nStr = n.ToString(); // multiple passes - first remove factors which can only appear in one location bool[] pUsed = new bool[distinctFactors.Length]; int pCount = 0; int numPasses = 3; for (int pass = 0; pass < numPasses && pCount < distinctFactors.Length; pass++) { for (int i = 0; i < distinctFactors.Length; i++) { if (pUsed[i]) continue; long p = distinctFactors[i]; int nCount = Regex.Matches(nStr, p.ToString()).Count; if (nCount < 1) { break; } else if (nCount == 1 || pass == numPasses - 1) { nStr = nStr.Replace(p.ToString(), "X"); pUsed[i] = true; pCount++; } } } nStr = nStr.Replace("X", ""); // note: we require all factors to be used without overlap return nStr == "" && pCount == distinctFactors.Count(); } public static bool IsA324259(long n, long[] distinctFactors, int[] fCount) { // subsequence of A324257 with every prime factor in n, not just distinct prime factors if (!IsA324257(n, distinctFactors)) return false; bool stat = true; string nStr = n.ToString(); for (int i = 0; i < distinctFactors.Length; i++) { long p = distinctFactors[i]; int nCount = Regex.Matches(nStr, p.ToString()).Count; if (nCount < fCount[i]) { // n doesn't contain enough copies of this factor stat = false; break; } } return stat; } } }