示例#1
0
        private void BtnFindNearPrime_Click(object sender, EventArgs e)
        {
            this.LastExec_IsPrime = false;

            IntTools.Normalize(this.IsPrimeInputValue);
            string str = this.IsPrimeInputValue.Text;

            if (IntTools.IsULongString(str) == false)
            {
                MessageBox.Show(
                    "0 ~ " + ulong.MaxValue + " の整数を入力して下さい。",
                    "判定できません",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning
                    );

                this.PostExec_IsPrime();
                return;
            }
            this.NennotameMkPrimeDat();

            WorkDir workDir = new WorkDir();
            string  outFile = workDir.MakePath();

            this.ProcMan.Start(Gnd.I.Prime64File, "//MOLP " + StringTools.OUT_PFX + " //O \"" + outFile + "\" " + this.CmdPartOptUMRTM() + "/LH " + str);

            using (BusyDlg f = new BusyDlg())
            {
                f.SetInterval(delegate
                {
                    return(this.ProcMan.IsEnd() == false);
                });

                f.ShowDialog();
            }
            string[] lines = File.ReadAllLines(outFile);
            lines = StringTools.Prime64StdoutFilter(lines);
            string str_l = lines[0];
            string str_h = lines[1];

            if (str_l == "0")
            {
                str_l = "(なし)";
            }

            if (str_h == "0")
            {
                str_h = Gnd.I.PRIME_MIN_OVER_UL;
            }

            this.IsPrimeOutput.Text = "入力値:\r\n" + str + "\r\n入力値より小さい最大の素数:\r\n" + str_l + "\r\n入力値より大きい最小の素数:\r\n" + str_h;
            //this.IsPrimeOutput.Text = "n=\r\n" + str + "\r\nnより小さい最大の素数=\r\n" + str_l + "\r\nnより大きい最小の素数=\r\n" + str_h;
            //this.IsPrimeOutput.Text = str + "\r\n" + str_l + "\r\n" + str_h + "\r\n\r\n# 上から「入力値, 入力値より小さい最大の素数, 入力値より大きい最小の素数」です。";
            //this.IsPrimeOutput.Text = str_l + "\r\n" + str_h + "\r\n\r\n# 上から「 " + str + " より小さい最大の素数」「 " + str + " より大きい最小の素数」です。素数が見つからない場合は 0 を表示します。";

            workDir.Destroy();
            workDir = null;

            this.PostExec_IsPrime();
        }
示例#2
0
        private bool Is空き不足()
        {
            try
            {
                string file = this.OutFile;

                if (StringTools.IsLocalDiskFullPath(file))
                {
                    DriveInfo di   = new DriveInfo(file[0] + ":");
                    long      size = di.TotalSize;
                    //long free = di.TotalFreeSpace;
                    long   free     = di.AvailableFreeSpace;
                    long   free_kb  = free / 1000;
                    long   free_mb  = free_kb / 1000;
                    double freeRate = (double)free / (double)size;
                    int    freePct  = IntTools.ToInt(freeRate * 100);

                    if (
                        freePct < Gnd.I.SettingData.DiskFreeOnOutput_Pct &&
                        free_mb < Gnd.I.SettingData.DiskFreeOnOutput_MB
                        )
                    {
                        return(true);
                    }
                }
            }
            catch
            { }

            return(false);
        }
示例#3
0
        private void BtnIsPrime_Click(object sender, EventArgs e)
        {
            this.LastExec_IsPrime = true;

            IntTools.Normalize(this.IsPrimeInputValue);
            string str = this.IsPrimeInputValue.Text;

            if (IntTools.IsULongString(str) == false)
            {
                MessageBox.Show(
                    "0 ~ " + ulong.MaxValue + " の整数を入力して下さい。",
                    "判定できません",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning
                    );

                this.PostExec_IsPrime();
                return;
            }
            this.NennotameMkPrimeDat();

            WorkDir workDir = new WorkDir();
            string  outFile = workDir.MakePath();

            this.ProcMan.Start(Gnd.I.Prime64File, "//MOLP " + StringTools.OUT_PFX + " //O \"" + outFile + "\" " + this.CmdPartOptUMRTM() + "/P " + str);

            using (BusyDlg f = new BusyDlg())
            {
                f.SetInterval(delegate
                {
                    return(this.ProcMan.IsEnd() == false);
                });

                f.ShowDialog();
            }
            string[] lines = File.ReadAllLines(outFile);
            lines = StringTools.Prime64StdoutFilter(lines);
            string ans = lines[0];

            if (ans == "IS_PRIME")
            {
                this.IsPrimeOutput.Text = str + "\r\nこの値は 素数 です。";
            }
            else if (ans == "IS_NOT_PRIME")
            {
                this.IsPrimeOutput.Text = str + "\r\nこの値は 素数 ではありません。2未満の整数又は合成数です。";
            }
            else
            {
                this.IsPrimeOutput.Text = str + "\r\n(エラー)";
            }
            workDir.Destroy();
            workDir = null;

            this.PostExec_IsPrime();
        }
示例#4
0
        private void BtnFactorize_Click(object sender, EventArgs e)
        {
            IntTools.Normalize(this.FactorizeInputValue);
            string str = this.FactorizeInputValue.Text;

            if (IntTools.IsULongString(str) == false || ulong.Parse(str) < 1)
            {
                MessageBox.Show(
                    "1 ~ " + ulong.MaxValue + " の整数を入力して下さい。",
                    "素因数分解できません",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning
                    );

                this.PostExec_Factorize();
                return;
            }
            this.NennotameMkPrimeDat();

            WorkDir workDir = new WorkDir();
            string  outFile = workDir.MakePath();

            this.ProcMan.Start(Gnd.I.Prime64File, "//MOLP " + StringTools.OUT_PFX + " //O \"" + outFile + "\" " + this.CmdPartOptUMRTM() + "/F " + str);

            using (BusyDlg f = new BusyDlg())
            {
                f.SetInterval(delegate
                {
                    return(this.ProcMan.IsEnd() == false);
                });

                f.ShowDialog();
            }
            string[] lines = File.ReadAllLines(outFile);
            lines = StringTools.Prime64StdoutFilter(lines);

            if (this.CheckFactorizeBekijou.Checked)
            {
                lines = this.ToBekijou(lines);
            }

            if (this.Chk改行しない.Checked)
            {
                this.FactorizeOutput.Text = str + " = " + string.Join(" * ", lines);
            }
            else
            {
                this.FactorizeOutput.Text = str + " の 素因数 は ...\r\n" + string.Join("\r\n", lines);
            }

            workDir.Destroy();
            workDir = null;

            this.PostExec_Factorize();
        }
示例#5
0
        private void US_Changed(bool normalizeFlag)
        {
            IntTools.CheckLongRange(this.US_L, US_X_MIN, US_X_MAX, normalizeFlag);
            IntTools.CheckLongRange(this.US_T, US_Y_MIN, US_Y_MAX, normalizeFlag);
            IntTools.CheckLongRange(this.US_R, US_X_MIN, US_X_MAX, normalizeFlag);
            IntTools.CheckLongRange(this.US_B, US_Y_MIN, US_Y_MAX, normalizeFlag);

            {
                long?w   = null;
                long?h   = null;
                long?wxh = null;

                try
                {
                    long l = IntTools.GetLongRange(this.US_L, US_X_MIN, US_X_MAX).Value;
                    long t = IntTools.GetLongRange(this.US_T, US_Y_MIN, US_Y_MAX).Value;
                    long r = IntTools.GetLongRange(this.US_R, US_X_MIN, US_X_MAX).Value;
                    long b = IntTools.GetLongRange(this.US_B, US_Y_MIN, US_Y_MAX).Value;

                    w = r - l + 1;
                    h = b - t + 1;

                    if (1 <= w && w < int.MaxValue && 1 <= h && h < int.MaxValue)
                    {
                        wxh = w * h;
                    }
                }
                catch
                { }

                this.SizeInfo.Text = "幅: " + w + "\n高さ: " + h + "\n幅×高さ: " + wxh;

                if (w == null || h == null || wxh == null)                 // ? 異常
                {
                    this.SizeInfo.ForeColor = Color.Red;
                }
                else if (US_W_H_MAX < w || US_W_H_MAX < h || US_WXH_MAX < wxh)                 // ? 大きすぎる
                {
                    this.SizeInfo.ForeColor = Color.OrangeRed;
                }
                else                 // ? 正常
                {
                    this.SizeInfo.ForeColor = IntTools.DEF_TB_FORECOLOR;
                }
            }
        }
示例#6
0
        public SettingData(string file)
        {
            try
            {
                this.Lines = File.ReadAllLines(file);

                this.KeepPrimeDat          = int.Parse(this.NextLine()) != 0;
                this.HidePrimeDat          = int.Parse(this.NextLine()) != 0;
                this.USCheckOff            = int.Parse(this.NextLine()) != 0;
                this.DiskFreeOnBoot_MB     = IntTools.ToInt(this.NextLine(), 1, IntTools.IMAX);
                this.DiskFreeOnOutput_Pct  = IntTools.ToInt(this.NextLine(), 0, 100);
                this.DiskFreeOnOutput_MB   = IntTools.ToInt(this.NextLine(), 1, IntTools.IMAX);
                this.CheckDiskFreeOnOutput = int.Parse(this.NextLine()) != 0;
                this.OutFileDiv            = int.Parse(this.NextLine()) != 0;
                this.LogInfo = int.Parse(this.NextLine()) != 0;
                this.UseMillerRabinTestMode = int.Parse(this.NextLine()) != 0;
                // ここへ追加
            }
            catch
            { }
            finally
            {
                this.Lines = null;

                WriteInfo("KeepPrimeDat: " + this.KeepPrimeDat);
                WriteInfo("HidePrimeDat: " + this.HidePrimeDat);
                WriteInfo("USCheckOff: " + this.USCheckOff);
                WriteInfo("DiskFreeOnBoot_MB: " + this.DiskFreeOnBoot_MB);
                WriteInfo("DiskFreeOnOutput_Pct: " + this.DiskFreeOnOutput_Pct);
                WriteInfo("DiskFreeOnOutput_MB: " + this.DiskFreeOnOutput_MB);
                WriteInfo("CheckDiskFreeOnOutput: " + this.CheckDiskFreeOnOutput);
                WriteInfo("OutFileDiv: " + this.OutFileDiv);
                WriteInfo("LogInfo: " + this.LogInfo);
                WriteInfo("UseMillerRabinTestMode: " + this.UseMillerRabinTestMode);
                // ここへ追加
            }
        }
示例#7
0
 private void PrimeCountMaxval_Leave(object sender, EventArgs e)
 {
     IntTools.Normalize(this.PrimeCountMaxval);
 }
示例#8
0
 private void PrimeCountMaxval_TextChanged(object sender, EventArgs e)
 {
     IntTools.CheckULong(this.PrimeCountMaxval);
 }
示例#9
0
 private void FactorizeInputValue_TextChanged(object sender, EventArgs e)
 {
     IntTools.CheckULong(this.FactorizeInputValue);
 }
示例#10
0
 private void IsPrimeInputValue_TextChanged(object sender, EventArgs e)
 {
     IntTools.CheckULong(this.IsPrimeInputValue);
 }
示例#11
0
 private void MaxValue_TextChanged(object sender, EventArgs e)
 {
     IntTools.CheckULong(this.MaxValue);
 }
示例#12
0
        private void BtnPrimeCount_Click(object sender, EventArgs e)
        {
            try
            {
                //IntTools.Normalize(this.PrimeCountMinval);
                //IntTools.Normalize(this.PrimeCountMaxval);

                string strmin = this.PrimeCountMinval.Text;
                string strmax = this.PrimeCountMaxval.Text;

                if (IntTools.IsULongString(strmin) == false)
                {
                    throw new Exception("[最小値] に 0 ~ " + ulong.MaxValue + " の整数を入力して下さい。");
                }

                if (IntTools.IsULongString(strmax) == false)
                {
                    throw new Exception("[最大値] に 0 ~ " + ulong.MaxValue + " の整数を入力して下さい。");
                }

                ulong minval = ulong.Parse(strmin);
                ulong maxval = ulong.Parse(strmax);

                if (maxval < minval)
                {
                    throw new Exception("[最小値] に [最大値] より大きな値が入力されています。");
                }

                string outFile = SaveLoadDialogs.SaveFile(
                    "出力ファイルを指定してください",
                    "テキスト:txt",
                    Directory.GetCurrentDirectory(),
                    "PrimeCount_" + minval + "-" + maxval + ".txt"
                    );

                if (outFile == null)
                {
                    return;
                }

                AppTools.CheckOutputFile(outFile);

                this.Visible = false;

                using (PrimeRangeOutputDlg f = new PrimeRangeOutputDlg(minval, maxval, outFile, true))
                {
                    f.ShowDialog();
                }
                this.Visible = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    ex.Message,
                    "出力できません",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning
                    );
            }
            finally
            {
                this.PrimeCountMinval.Focus();
                //this.PrimeCountMinval.SelectAll(); // 勝手に全セレクトされる。
            }
        }
示例#13
0
 private void IsPrimeInputValue_Leave(object sender, EventArgs e)
 {
     IntTools.Normalize(this.IsPrimeInputValue);
 }
示例#14
0
 private void MaxValue_Leave(object sender, EventArgs e)
 {
     IntTools.Normalize(this.MaxValue);
 }
示例#15
0
        private void MainWin_Load(object sender, EventArgs e)
        {
            this.MinimumSize = this.Size;

            {
                bool existsPrimeDat;

                using (Mutex m = new Mutex(false, Gnd.I.FACTORY_COMMON_MUTEX))
                    using (new IMutex(m))
                    {
                        existsPrimeDat = File.Exists("Prime.dat");
                    }
                if (existsPrimeDat == false)
                {
                    // Prime.dat のため、ディスクの空きチェック
                    {
                        DriveInfo di          = new DriveInfo(BootTools.SelfDir.Substring(0, 2));
                        int       diskFree_mb = IntTools.ToInt(di.AvailableFreeSpace / 1000000.0);

                        if (diskFree_mb < Gnd.I.SettingData.DiskFreeOnBoot_MB)                         // ? < 300 MB
                        {
                            string message = "起動に必要なディスクの空き領域が不足しています。(" + diskFree_mb + "_" + Gnd.I.SettingData.DiskFreeOnBoot_MB + ")";

                            MessageBox.Show(message, Program.APP_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            throw new Exception(message);
                        }
                    }

#if true
                    {
                        ProcessStartInfo psi = new ProcessStartInfo();

                        psi.FileName        = Gnd.I.Prime64File;
                        psi.Arguments       = "/P 1";
                        psi.CreateNoWindow  = true;
                        psi.UseShellExecute = false;

                        Process.Start(psi);                         // 待たない!
                    }
#else // old @ 2017.5.17
                    this.ProcMan.Start(Gnd.I.Prime64File, "/P 1");

                    using (BusyDlg f = new BusyDlg())
                    {
                        f.SetInterval(delegate
                        {
                            return(this.ProcMan.IsEnd() == false);
                        });
                        f.SetMessage("データファイルを作成しています...");
                        f.ShowDialog();

                        this.Location = f.Location;
                    }

                    if (Gnd.I.SettingData.HidePrimeDat)
                    {
                        this.ProcMan.Start("ATTRIB.EXE", "+S +H Prime.dat");
                        this.ProcMan.End();
                    }
#endif
                }
            }
        }
示例#16
0
        private void Btn_US_Click(object sender, EventArgs e)
        {
            try
            {
                this.US_Changed(true);

                long l;
                long t;
                long r;
                long b;

                try
                {
                    l = IntTools.GetLongRange(this.US_L, US_X_MIN, US_X_MAX).Value;
                    t = IntTools.GetLongRange(this.US_T, US_Y_MIN, US_Y_MAX).Value;
                    r = IntTools.GetLongRange(this.US_R, US_X_MIN, US_X_MAX).Value;
                    b = IntTools.GetLongRange(this.US_B, US_Y_MIN, US_Y_MAX).Value;
                }
                catch
                {
                    throw new Exception("座標の書式に問題があります。");
                }

                if (Gnd.I.SettingData.USCheckOff == false)
                {
                    if (r < l)
                    {
                        throw new Exception("[右下X] < [左上X] になっています。");
                    }

                    if (b < t)
                    {
                        throw new Exception("[右下Y] < [左上Y] になっています。");
                    }

                    long w = r - l + 1;
                    long h = b - t + 1;

                    if (US_W_H_MAX < w)
                    {
                        throw new Exception("[幅] は " + US_W_H_MAX + " 以下でなければなりません。");
                    }

                    if (US_W_H_MAX < h)
                    {
                        throw new Exception("[高さ] は " + US_W_H_MAX + " 以下でなければなりません。");
                    }

                    long wxh = w * h;

                    if (US_WXH_MAX < wxh)
                    {
                        throw new Exception("[幅×高さ] は " + US_WXH_MAX + " 以下でなければなりません。");
                    }
                }

                this.EC_Load(this.BtnPrimeColor);
                string primeColor = this.EC_RefStrColor;
                this.EC_Load(this.BtnNotPrimeColor);
                string notPrimeColor = this.EC_RefStrColor;
                this.EC_Load(this.BtnCenterColor);
                string centerColor = this.EC_RefStrColor;

                string outFile = SaveLoadDialogs.SaveFile(
                    "出力ファイルを指定してください",
                    "ビットマップ:bmp",
                    Directory.GetCurrentDirectory(),
                    "UlamSpiral_" + l + "_" + t + "_" + r + "_" + b + ".bmp"
                    );

                if (outFile == null)
                {
                    return;
                }

                AppTools.CheckOutputFile(outFile);

                this.Visible = false;

                using (UlamSpiralOutputDlg f = new UlamSpiralOutputDlg(l, t, r, b, primeColor, notPrimeColor, centerColor, outFile))
                {
                    f.ShowDialog();
                }
                this.Visible = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    ex.Message,
                    "BMPファイルを出力できません",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning
                    );
            }
            finally
            {
                this.US_L.Focus();
                //this.US_L.SelectAll(); // 勝手に全セレクトされる。
            }
        }
示例#17
0
 private void FactorizeInputValue_Leave(object sender, EventArgs e)
 {
     IntTools.Normalize(this.FactorizeInputValue);
 }