Exemplo n.º 1
0
        private void Btn判定_Click(object sender, EventArgs e)
        {
            string text = "";

            using (this.MTBusy.Section())
            {
                try
                {
                    string value = this.T判定_入力.Text;

                    if (value == "")
                    {
                        throw new Exception("未入力です。");
                    }

                    if (StringTools.LiteValidate(value, StringTools.DECIMAL) == false)
                    {
                        throw new Exception("[0-9] 以外の文字が含まれています。");
                    }

                    if (Ground.TCalc_Int.Calc(Consts.S2P4096_1, "-", value)[0] == '-')
                    {
                        throw new LongMessageException(Utils.AutoInsertNewLine("0 以上 " + Consts.S2P4096_1 + " 以下の整数を入力して下さい。", Consts.MaxLineLen_LongMessageDlg));
                    }

                    this.Visible = false;

                    BusyDlgTools.Show("Prime4096", "素数かどうか判定しています...", () =>
                    {
                        text = value + "\r\n----> " + (Prime4096.IsPrime(value) ? "素数です。" : "素数ではありません。");
                    }
                                      );
                }
                catch (Exception ex)
                {
                    this.CommonCought(ex);
                }
            }
            this.Visible = true;             // 復元

            this.T判定_結果.Text           = text;
            this.T判定_結果.SelectionStart = this.T判定_結果.TextLength;
            this.T判定_結果.ScrollToCaret();
        }
Exemplo n.º 2
0
        private void Btn個数_Click(object sender, EventArgs e)
        {
            using (this.MTBusy.Section())
            {
                try
                {
                    string minval = this.T個数_最小値.Text;
                    string maxval = this.T個数_最大値.Text;

                    if (minval == "")
                    {
                        throw new Exception("最小値 が 未入力です。");
                    }

                    if (maxval == "")
                    {
                        throw new Exception("最大値 が 未入力です。");
                    }

                    if (StringTools.LiteValidate(minval, StringTools.DECIMAL) == false)
                    {
                        throw new Exception("最小値 に [0-9] 以外の文字が含まれています。");
                    }

                    if (StringTools.LiteValidate(minval, StringTools.DECIMAL) == false)
                    {
                        throw new Exception("最大値 に [0-9] 以外の文字が含まれています。");
                    }

                    if (Ground.TCalc_Int.Calc(Consts.S2P4096_1, "-", minval)[0] == '-')
                    {
                        throw new LongMessageException(Utils.AutoInsertNewLine("最小値 には 0 以上 " + Consts.S2P4096_1 + " 以下の整数を入力して下さい。", Consts.MaxLineLen_LongMessageDlg));
                    }

                    if (Ground.TCalc_Int.Calc(Consts.S2P4096_1, "-", maxval)[0] == '-')
                    {
                        throw new LongMessageException(Utils.AutoInsertNewLine("最大値 には 0 以上 " + Consts.S2P4096_1 + " 以下の整数を入力して下さい。", Consts.MaxLineLen_LongMessageDlg));
                    }

                    if (Ground.TCalc_Int.Calc(maxval, "-", minval)[0] == '-')
                    {
                        throw new Exception("最大値 < 最小値 になっています。");
                    }

                    string outFile = "PrimeCount_" + minval + "-" + maxval + ".txt";

                    if (Consts.OutputLocalFileLenMax < outFile.Length)
                    {
                        //outFile = "PrimeCount.txt";
                        outFile = "PrimeCount_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt";
                    }

                    //outFile = Path.Combine(ProcMain.SelfDir, outFile);
                    outFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), outFile);

                    outFile = InputFileDlgTools.Save(
                        "Prime4096",
                        "出力ファイルを選択して下さい。",
                        true,
                        outFile,
                        null,
                        "txt"
                        );

                    if (outFile == null)
                    {
                        throw new Returning();
                    }

                    bool[] cancelledBox = new bool[1];

                    this.Visible = false;
                    this.CommonInterlude_INIT(currValue => string.Format("{0} あたりの素数を数えています...", currValue));

                    WaitDlgTools.Show(
                        "Prime4096",
                        "数えています...",
                        () => Prime4096.WritePrimeCount(minval, maxval, outFile, () => cancelledBox[0] == false),
                        this.CommonInterlude,
                        () => cancelledBox[0] = true
                        );

                    if (WaitDlg.LastCancelled)
                    {
                        // memo: Prime4096.exe, Prime53.exe は ABORTED 行等を出力しない。

                        File.WriteAllText(
                            outFile,
                            File.ReadAllText(outFile, Encoding.ASCII).Trim() + "\n中止しました。\nこの出力結果は正しくない可能性があります。",
                            StringTools.ENCODING_SJIS
                            );

                        MessageDlgTools.Show(MessageDlg.Mode_e.Warning, "Prime4096", "中止しました。\r\n出力ファイルの内容は正しくない可能性があります。");
                    }
                    else
                    {
                        MessageDlgTools.Information("Prime4096", "完了しました。");
                    }
                }
                catch (Exception ex)
                {
                    this.CommonCought(ex);
                }
            }
            this.Visible = true;             // 復元
        }
Exemplo n.º 3
0
        private void MainWin_Shown(object sender, EventArgs e)
        {
            // -- 0001

            // TODO WriteLog = write to .log file

            ExtraTools.AntiWindowsDefenderSmartScreen();

            Prime4096.INIT();
            Prime53Lite.INIT();

            Prime53Lite.GeneratePrimeDat();

            this.Base_MainWin_H = this.Height;
            this.Base_T1_H      = this.T出力_最小値.Height;
            this.Base_L2_T      = this.L出力_最大値.Top;
            this.Base_T2_T      = this.T出力_最大値.Top;
            this.Base_T2_H      = this.T出力_最大値.Height;

            this.Base2_T1_H = this.T判定_入力.Height;
            this.Base2_B1_T = this.Btn判定.Top;
            this.Base2_T2_T = this.T判定_結果.Top;
            this.Base2_T2_H = this.T判定_結果.Height;

            // --

            this.T出力_最小値.Text = "" + 2;
            this.T出力_最大値.Text = "" + 10000000000;

            this.T判定_入力.Text = Consts.S2P1279_1;
            this.T判定_結果.Text = "";

            this.T探索_入力.Text = ("" + 1) + StringTools.Repeat("0", 400);
            this.T探索_結果.Text = "";

            this.T素因数分解_入力.Text = Consts.SMP1000;
            this.T素因数分解_結果.Text = "";

            this.T個数_最小値.Text = "" + 2;
            this.T個数_最大値.Text = "" + 10000000000;

            // --

            this.T出力_最小値.SelectAll();
            this.T出力_最大値.SelectAll();

            this.T判定_入力.SelectAll();

            this.T探索_入力.SelectAll();

            this.T素因数分解_入力.SelectAll();

            this.T個数_最小値.SelectAll();
            this.T個数_最大値.SelectAll();

            // --

            this.MainToolTip.SetToolTip(this.T出力_最小値, Utils.AutoInsertNewLine("0 以上 " + Consts.S2P4096_1 + " 以下の整数を入力して下さい。", Consts.MaxLineLen_ToolTip));
            this.MainToolTip.SetToolTip(this.T出力_最大値, Utils.AutoInsertNewLine("0 以上 " + Consts.S2P4096_1 + " 以下の整数を入力して下さい。", Consts.MaxLineLen_ToolTip));

            this.MainToolTip.SetToolTip(this.T判定_入力, Utils.AutoInsertNewLine("0 以上 " + Consts.S2P4096_1 + " 以下の整数を入力して下さい。", Consts.MaxLineLen_ToolTip));

            this.MainToolTip.SetToolTip(this.T探索_入力, Utils.AutoInsertNewLine("0 以上 " + Consts.S2P4096_1 + " 以下の整数を入力して下さい。", Consts.MaxLineLen_ToolTip));

            this.MainToolTip.SetToolTip(this.T素因数分解_入力, Utils.AutoInsertNewLine("1 以上 " + Consts.S2P4096_1 + " 以下の整数を入力して下さい。", Consts.MaxLineLen_ToolTip));

            this.MainToolTip.SetToolTip(this.T個数_最小値, Utils.AutoInsertNewLine("0 以上 " + Consts.S2P4096_1 + " 以下の整数を入力して下さい。", Consts.MaxLineLen_ToolTip));
            this.MainToolTip.SetToolTip(this.T個数_最大値, Utils.AutoInsertNewLine("0 以上 " + Consts.S2P4096_1 + " 以下の整数を入力して下さい。", Consts.MaxLineLen_ToolTip));

            // ----

            this.RefreshUI();

            ChocomintDialogsCommon.PostShown(this);

            // ----

            this.MTBusy.Leave();
        }
Exemplo n.º 4
0
        private void Btn素因数分解_Click(object sender, EventArgs e)
        {
            string text = "";

            using (this.MTBusy.Section())
            {
                try
                {
                    string value = this.T素因数分解_入力.Text;

                    if (value == "")
                    {
                        throw new Exception("未入力です。");
                    }

                    if (StringTools.LiteValidate(value, StringTools.DECIMAL) == false)
                    {
                        throw new Exception("[0-9] 以外の文字が含まれています。");
                    }

                    if (
                        Ground.TCalc_Int.Calc(value, "-", "1")[0] == '-' ||
                        Ground.TCalc_Int.Calc(Consts.S2P4096_1, "-", value)[0] == '-'
                        )
                    {
                        throw new LongMessageException(Utils.AutoInsertNewLine("1 以上 " + Consts.S2P4096_1 + " 以下の整数を入力して下さい。", Consts.MaxLineLen_LongMessageDlg));
                    }

                    bool[] cancelledBox = new bool[1];

                    this.Visible = false;
                    this.CommonInterlude_INIT(currValue => string.Format("素因数分解しています... {0}", currValue));

                    WaitDlgTools.Show(
                        "Prime4096",
                        "素因数分解しています...",
                        () => text = string.Join("\r\n", Prime4096.Factorization(value, () => cancelledBox[0] == false)),
                        this.CommonInterlude,
                        () => cancelledBox[0] = true
                        );

                    if (WaitDlg.LastCancelled)
                    {
                        //text += "\r\n中止しました。この出力結果は正しくない可能性があります。"; // old

                        text =
                            "中止しました。\r\n" +
                            "この出力結果は正しくない可能性があります。\r\n" +
                            text;
                    }
                }
                catch (Exception ex)
                {
                    this.CommonCought(ex);
                }
            }
            this.Visible = true;             // 復元

            this.T素因数分解_結果.Text = text;
            //this.T素因数分解_結果.SelectionStart = this.T素因数分解_結果.TextLength;
            //this.T素因数分解_結果.ScrollToCaret();
        }
Exemplo n.º 5
0
        private void Btn探索_Click(object sender, EventArgs e)
        {
            string text = "";

            using (this.MTBusy.Section())
            {
                try
                {
                    string value = this.T探索_入力.Text;

                    if (value == "")
                    {
                        throw new Exception("未入力です。");
                    }

                    if (StringTools.LiteValidate(value, StringTools.DECIMAL) == false)
                    {
                        throw new Exception("[0-9] 以外の文字が含まれています。");
                    }

                    if (Ground.TCalc_Int.Calc(Consts.S2P4096_1, "-", value)[0] == '-')
                    {
                        throw new LongMessageException(Utils.AutoInsertNewLine("0 以上 " + Consts.S2P4096_1 + " 以下の整数を入力して下さい。", Consts.MaxLineLen_LongMessageDlg));
                    }

                    bool[] cancelledBox = new bool[1];

                    this.Visible = false;
                    this.CommonInterlude_INIT();

                    WaitDlgTools.Show(
                        "Prime4096",
                        "最寄りの素数を探しています...",
                        () =>
                    {
                        //WaitDlg.MessagePost.Post("最寄りの素数を探しています... (小さい方)");
                        this.WD_ProgressRate = 0.333;
                        string lowerPrime    = Prime4096.GetLowerPrime(value, () => cancelledBox[0] == false);
                        //WaitDlg.MessagePost.Post("最寄りの素数を探しています... (大きい方)");
                        this.WD_ProgressRate = 0.666;
                        string higherPrime   = Prime4096.GetHigherPrime(value, () => cancelledBox[0] == false);

                        if (lowerPrime == "0")
                        {
                            lowerPrime = "none";
                        }

                        text = string.Join("\r\n",
                                           "元の数より小さい最大の素数 ---->",
                                           lowerPrime,
                                           "",
                                           "元の数より大きい最小の素数 ---->",
                                           higherPrime,
                                           "",
                                           "元の数 ---->",
                                           value
                                           );
                    },
                        this.CommonInterlude,
                        () => cancelledBox[0] = true
                        );

                    if (WaitDlg.LastCancelled)
                    {
                        text = "中止しました。";
                    }
                }
                catch (Exception ex)
                {
                    this.CommonCought(ex);
                }
            }
            this.Visible = true;             // 復元

            this.T探索_結果.Text = text;
            //this.T探索_結果.SelectionStart = this.T探索_結果.TextLength;
            //this.T探索_結果.ScrollToCaret();
        }