Example #1
0
        internal static string Prime_digit_replacements_old()
        {
            List <Int64>  primes    = MathProblemsLibrary.Primes.GetBelov(999999);
            List <string> primesStr = new List <string>();

            foreach (var prime in primes)
            {
                primesStr.Add(prime.ToString());
            }
            List <string> result = new List <string>();
            Dictionary <int, List <string> > listMask = CreateMaskList();
            List <string> checkMaskList = new List <string>();
            int           i             = 0;

            foreach (var primeStr in primesStr)
            {
                List <string> masks = listMask[primeStr.Length];
                foreach (var mask in masks)
                {
                    result = BuildList(mask, primesStr, i, primeStr, result);
                    if (result.Count >= 8)
                    {
                        foreach (var val in result)
                        {
                            MathsProblemsForm.Log(val.ToString());
                        }
                        return(result[0].ToString());
                    }
                }
                i++;
            }
            return("");
        }
Example #2
0
        internal static string Combinatoric_selections()
        {
            string f1     = "";
            string f2     = "";
            string f3     = "";
            string sum    = "";
            string divide = "";
            int    count  = 0;

            for (int n = 23; n <= 100; n++)
            {
                for (int r = 1; r < n; r++)
                {
                    f1     = MathProblemsLibrary.LargeDigitsDestroyer.Faktorial(n);
                    f2     = MathProblemsLibrary.LargeDigitsDestroyer.Faktorial(r);
                    f3     = MathProblemsLibrary.LargeDigitsDestroyer.Faktorial(n - r);
                    sum    = MathProblemsLibrary.LargeDigitsDestroyer.Multiplication_Two_Huge_Digits(f2, f3);
                    divide = MathProblemsLibrary.LargeDigitsDestroyer.Divide_Two_Huge_Digits(f1, sum);
                    if (CheckDigit(divide, "1000000"))
                    {
                        MathsProblemsForm.Log(n.ToString() + "  " + r.ToString() + " = " + divide);
                        count++;
                    }
                }
            }
            return(count.ToString());
        }
        private void RunTest(DecisionProblemMethod method)
        {
            if (method == null)
            {
                return;
            }

            this.ResultTextBox.Clear();
            var task = new Task(() => {
                MathsProblemsForm.Log("========================Start=======================");
                MathsProblemsForm.Log(method.ToString());
                var watch = System.Diagnostics.Stopwatch.StartNew();
                var res   = method();
                watch.Stop();
                string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                                   watch.Elapsed.Hours, watch.Elapsed.Minutes, watch.Elapsed.Seconds,
                                                   watch.Elapsed.Milliseconds / 10);
                MathsProblemsForm.Log("========================Finnish=====================");
                MathsProblemsForm.Log("Result:");
                MathsProblemsForm.Log(res);
                MathsProblemsForm.Log("");
                MathsProblemsForm.Log("Time: ");
                MathsProblemsForm.Log(elapsedTime);
                MathsProblemsForm.Log("========================Finnish=====================");
            });

            task.Start();
        }
Example #4
0
        internal static string Consecutive_prime_sum()
        {
            List <Int64> primeList = MathProblemsLibrary.Primes.GetBelov(1000000);
            Dictionary <Int64, Int64> resValList = new Dictionary <Int64, Int64> {
            };
            Int64 maxVal = 0;
            Int64 val    = 0;

            for (int i = 2; i < primeList.Count; i++)
            {
                int k = i;
                while (k >= 0)
                {
                    k--;
                    Int64 sum   = 0;
                    int   count = 0;
                    for (int j = k; j >= 0; j--)
                    {
                        sum += primeList[j];
                        count++;
                        if (sum >= primeList[i])
                        {
                            break;
                        }
                    }
                    if (sum == primeList[i] && count > maxVal)
                    {
                        val    = primeList[i];
                        maxVal = count;
                        MathsProblemsForm.Log(val.ToString() + "    " + maxVal.ToString());
                    }
                }
            }
            return(val.ToString());
        }
Example #5
0
        internal static string Largest_prime_factor()
        {
            var primes = Divisors.GetPrimeListOfDivisors(n);

            foreach (var prime in primes)
            {
                MathsProblemsForm.Log(prime.ToString());
            }
            var maxPrime = primes[primes.Count - 1];

            return(maxPrime.ToString());
        }
Example #6
0
        internal static string Digit_cancelling_fractions()
        {
            List <int> digits = new List <int> {
            };
            int result        = 0;
            int res           = 0;
            int res2          = 0;
            int newNum        = 0;
            int newDenum      = 0;
            int prodnewNum    = 1;
            int prodnewDenum  = 1;

            for (int i = 10; i < 100; i++)
            {
                digits.Add(i);
            }
            for (int i = 0; i < digits.Count; i++)
            {
                for (int j = i + 1; j < digits.Count; j++)
                {
                    if ((digits[j] % 10 != 0 && digits[i] % 10 != 0) &&
                        (Check_numerator_and_denominator(digits[i], digits[j])))
                    {
                        string numStr   = digits[i].ToString();
                        string denumStr = digits[j].ToString();
                        for (int k = 0; k < numStr.Length; k++)
                        {
                            if (numStr.IndexOf(denumStr[k]) >= 0)
                            {
                                newNum   = int.Parse(numStr.Remove(numStr.IndexOf(denumStr[k]), 1));
                                newDenum = int.Parse(denumStr.Remove(denumStr.IndexOf(denumStr[k]), 1));
                            }
                        }
                        res  = digits[j] / digits[i];
                        res2 = newDenum / newNum;
                        if ((digits[i] % newNum == 0 && digits[i] / newNum * newDenum == digits[j] && digits[j] / digits[i] == newDenum / newNum && digits[j] / digits[i] != 1 && newDenum / newNum != 1) ||
                            (res == res2 && digits[j] % digits[i] == 0 && newDenum % newNum == 0))
                        {
                            prodnewNum   = prodnewNum * digits[i];
                            prodnewDenum = prodnewDenum * digits[j];
                            MathsProblemsForm.Log(digits[i].ToString() + " / " + digits[j].ToString() + " = " + res.ToString() +
                                                  "      " + newNum.ToString() + " / " + newDenum.ToString() + " = " + res2.ToString());
                        }
                    }
                }
            }
            result = prodnewDenum / prodnewNum;
            return(result.ToString());
        }
Example #7
0
        internal static string Circular_primes()
        {
            List <Int64> primeList = MathProblemsLibrary.Primes.GetBelov(maxVal);
            int          count     = 0;

            for (int i = 0; i < primeList.Count; i++)
            {
                if (Val_in_list(primeList[i], primeList))
                {
                    MathsProblemsForm.Log(primeList[i].ToString());
                    count++;
                }
            }
            return(count.ToString());
        }
Example #8
0
        internal static string Truncatable_primes()
        {
            List <Int64> primeList = MathProblemsLibrary.Primes.GetBelov(maxVal);
            Int64        sum       = 0;

            for (int i = 4; i < primeList.Count; i++)
            {
                if (Val_In_List_Start(primeList[i], primeList) && Val_In_List_End(primeList[i], primeList))
                {
                    MathsProblemsForm.Log("Val =" + primeList[i].ToString());
                    sum += primeList[i];
                }
            }
            return(sum.ToString());
        }
Example #9
0
        internal static string Reciprocal_cycles()
        {
            int    digit     = 10;
            int    reultMax  = 0;
            string resultStr = "";
            string strDigit  = "";

            for (int i = 2; i < d; i++)
            {
                strDigit = LargeDigitsDestroyer.DivisionOfNatural(digit, i);
                MathsProblemsForm.Log(i.ToString() + "\t" + strDigit);
                if (strDigit.Length > reultMax)
                {
                    reultMax  = strDigit.Length;
                    resultStr = strDigit;
                }
            }
            return(resultStr);
        }
Example #10
0
        internal static string Prime_permutations()
        {
            var primeList   = MathProblemsLibrary.Primes.GetBelov(10000);
            var reListPrime = new List <Int64> {
            };
            var reList      = new List <long> {
            };
            var resultList  = new List <long> {
            };
            string re       = "";

            for (int i = 0; i < primeList.Count; i++)
            {
                if (primeList[i] > 999)
                {
                    reListPrime.Add(primeList[i]);
                }
            }
            for (int i = 0; i < reListPrime.Count; i++)
            {
                reList.Clear();
                reList.Add(reListPrime[i]);
                for (int j = i + 1; j < reListPrime.Count; j++)
                {
                    if (Check_permutatiom(reListPrime[i].ToString(), reListPrime[j].ToString()))
                    {
                        reList.Add(reListPrime[j]);
                        reListPrime.Remove(reListPrime[j]);
                    }
                }
                resultList = Check_Sum(reList);
                if (resultList.Count >= 3)
                {
                    for (int r = 0; r < resultList.Count; r++)
                    {
                        re += resultList[r].ToString();
                    }
                    MathsProblemsForm.Log(re);
                }
                re = "";
            }
            return("");
        }
Example #11
0
        internal static string Lychrel_numbers()
        {
            int result = 0;

            for (int i = 1; i < 10000; i++)
            {
                string summ  = "12";
                int    count = 0;
                string val1  = i.ToString();

                while (!IsPalindrom(summ))
                {
                    string      val2 = "";
                    List <char> vl2  = new List <char>();

                    foreach (var val in val1)
                    {
                        vl2.Insert(0, val);
                    }
                    foreach (var value in vl2)
                    {
                        val2 += value;
                    }

                    summ = MathProblemsLibrary.LargeDigitsDestroyer.Summ_Two_Huge_Digits(val1, val2);
                    count++;
                    //MathsProblemsForm.Log(val1 + "+" + val2 + "==" + summ);
                    if (count == 50)
                    {
                        break;
                    }
                    val1 = summ;
                }
                if (count == 50)
                {
                    result++;
                    MathsProblemsForm.Log(i.ToString() + "(" + count.ToString() + ")");
                }
            }
            return(result.ToString());
        }
Example #12
0
            internal static string Numbers_Summ(Int64 value)
            {
                Int64  digits     = 0;
                Int64  digitsTemp = 0;
                Int64  sum        = 0;
                string strTemp    = "1";
                string strResult  = "";

                for (int j = 0; j < value; j++)
                {
                    for (int i = strTemp.Length - 1; i >= 0; i--)
                    {
                        digits     = CharToInt(strTemp[i]);
                        digitsTemp = digits + value + sum;
                        if (digitsTemp >= 10)
                        {
                            digits    = digitsTemp % 10;
                            sum       = (digitsTemp - (digitsTemp % 10)) / 10;
                            strResult = digits.ToString() + strResult;
                        }
                        else
                        {
                            sum       = 0;
                            strResult = digitsTemp.ToString() + strResult;
                        }
                    }
                    if (digitsTemp >= 10)
                    {
                        sum       = (digitsTemp - digits) / 10;
                        strResult = sum + strResult;
                    }
                    sum     = 0;
                    strTemp = strResult;
                    MathsProblemsForm.Log(strResult);
                    strResult = "";
                }
                return(strTemp);
            }
Example #13
0
        internal static string Triangular_pentagonal_and_hexagonal()
        {
            Int64 trian       = 0;
            Int64 penta       = 0;
            Int64 hexag       = 0;
            Int64 tempj       = 1;
            Int64 tempk       = 1;
            int   resultCount = 0;

            for (Int64 i = 285; trian < Int64.MaxValue / 2; i++)
            {
                trian = (i * (i + 1)) / 2;
                for (Int64 j = tempj; penta <= trian; j++)
                {
                    penta = (j * (3 * j - 1)) / 2;
                    if (trian == penta)
                    {
                        for (Int64 k = tempk; hexag <= trian; k++)
                        {
                            hexag = k * (2 * k - 1);
                            if (hexag == trian)
                            {
                                resultCount++;
                                MathsProblemsForm.Log(trian.ToString() + " " + i.ToString() + " " + j.ToString() + " " + k.ToString());
                                if (resultCount == 2)
                                {
                                    return(trian.ToString());
                                }
                            }
                            tempk = k;
                        }
                    }
                    tempj = j;
                }
            }
            return("");
        }
Example #14
0
        internal static string Pentagon_numbers()
        {
            int        pent     = 0;
            List <int> pentList = new List <int> {
            };
            int minVal          = 10000000;
            int didifference    = 0;
            int sum             = 0;

            for (int i = 1; i < 10000; i++)
            {
                pent = i * (3 * i - 1) / 2;
                if (pent > 0)
                {
                    pentList.Add(pent);
                }
            }
            for (int j = 0; j < pentList.Count; j++)
            {
                for (int k = j + 1; k < pentList.Count; k++)
                {
                    sum          = pentList[k] + pentList[j];
                    didifference = pentList[k] - pentList[j];
                    if (Is_Pentagon(didifference, pentList) && Is_Pentagon(sum, pentList))
                    {
                        if (didifference < minVal)
                        {
                            MathsProblemsForm.Log(pentList[k].ToString() + "  " + pentList[j].ToString() + "    " + didifference.ToString());
                            minVal = didifference;
                            return(minVal.ToString());
                        }
                    }
                }
            }
            return(minVal.ToString());
        }
Example #15
0
        internal static string Sub_string_divisibility()
        {
            List <Int64> valList = new List <Int64> {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 0
            };

            Int64        res            = 0;
            string       strDigit       = "";
            List <Int64> listPandigital = new List <Int64> {
            };

            listPandigital = Build_Pandigital_Digits(valList.Count, valList);
            for (int i = 0; i < listPandigital.Count; i++)
            {
                strDigit = listPandigital[i].ToString();
                if (MathProblemsLibrary.OthertFuncktion.Check_Pandigital_products(strDigit, 10) &&
                    Check_property(strDigit))
                {
                    res += listPandigital[i];
                    MathsProblemsForm.Log(listPandigital[i].ToString());
                }
            }
            return(res.ToString());
        }
Example #16
0
        internal static string Distinct_primes_factors2()
        {
            var listPrimes = MathProblemsLibrary.Primes.GetBelov(1000000);
            var divList    = new List <Int64> {
            };
            var reList     = new List <Int64> {
            };
            var dictResult = new Dictionary <Int64, bool> {
            };
            int tempRe     = 1;

            for (Int64 i = 2; i < 1000000; i++)
            {
                divList = GetDivisors(i);
                reList.Clear();
                if (divList.Count == 4)
                {
                    foreach (var div in divList)
                    {
                        if ((listPrimes.IndexOf(div) >= 0 || Check_Degree(div) != 0) && reList.IndexOf(div) < 0)
                        {
                            reList.Add(div);
                        }
                    }
                    if (reList.Count == 4)
                    {
                        MathsProblemsForm.Log(i.ToString());
                        dictResult.Add(i, true);
                        if (dictResult.ContainsKey(i - 1))
                        {
                            tempRe += 1;
                            if (tempRe == 4)
                            {
                                return((i - 3).ToString());
                            }
                        }
                        else
                        {
                            tempRe = 1;
                        }
                    }
                }
                //divList = MathProblemsLibrary.Divisors.GetList(i,false);
                //listPrimes = MathProblemsLibrary.Primes.GetBelov(i);
                //reList.Clear();
                //foreach (var div in divList)
                //{

                //    if (listPrimes.IndexOf(div) >= 0)
                //        reList.Add(div);
                //    else
                //    {
                //        Int64 temp = Check_Degree(div);
                //        if (temp > 0 && reList.IndexOf(temp) < 0)
                //            reList.Add(div);
                //    }
                //}
                //sumary = 1;
                //foreach (var rel in reList)
                //{
                //    sumary = sumary * rel;
                //}
                //if ((reList.Count == 4) && (sumary == i))
                //{


                //    //string str = i.ToString() + " = ";
                //    //foreach (var rl in reList)
                //    //{
                //    //    str += rl.ToString() + " x ";
                //    //}
                //    //MathsProblemsForm.Log(str);



                //    dictResult.Add(i, true);
                //    if (dictResult.ContainsKey(i - 1))
                //    {
                //        MathsProblemsForm.Log(i.ToString());
                //        tempRe += 1;
                //        if (tempRe == 4)
                //            return (i - 3).ToString();
                //    }
                //    else
                //        tempRe = 1;
                //}



                ////var reList = new List<Int64> { };
                ////for (int j = 0; j < divList.Count; j++)
                ////{
                ////    if (reList.IndexOf(divList[j]) < 0)
                ////    {
                ////        reList.Add(divList[j]);
                ////    }
                ////}
                ////if (reList.Count != 4)
                ////{
                ////    string str = i.ToString() + "= ";
                ////    foreach (var rl in reList)
                ////    {
                ////        str += rl.ToString() + "x";
                ////    }
                ////    MathsProblemsForm.Log(str);
                ////    dictResult.Add(i, true);
                ////    if (dictResult.ContainsKey(i - 1))
                ////    {
                ////        tempRe += 1;
                ////        if (tempRe == 4)
                ////            return i.ToString();
                ////    }
                ////    else
                ////        tempRe = 1;
                ////}
            }
            return("");
        }