-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckPrime.cs
More file actions
129 lines (117 loc) · 3.74 KB
/
Copy pathCheckPrime.cs
File metadata and controls
129 lines (117 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class CheckPrime
{
public List<string> arraySimpleNumb = new List<string>();
public bool CheckNumb(int numb)
{
for (int i = 2; i <= Math.Sqrt(numb); i++)
{
if(numb % i == 0)
{
return false;
}
}
return true;
}
private void FillList(int numb)
{
bool simpleNumb;
int valueMax = numb.ToString().Length;
int valueMin;
String maxValue = "";
String minValue = "1";
for (int i = 0; i < valueMax; i++)
{
maxValue = maxValue + "9";
if(i!=valueMax-1)
{
minValue = minValue + "0";
}
}
valueMax = Convert.ToInt32(maxValue);
valueMin = Convert.ToInt32(minValue);
for (int i = valueMin; i < valueMax; i++ )
{
simpleNumb = CheckNumb(i);
if (simpleNumb)
{
arraySimpleNumb.Add(i.ToString());
}
}
}
public int Factorial(int numb)
{
if (numb == 0)
{
return 1;
}
else
{
return numb * Factorial(numb - 1);
}
}
public int UnicDigit(int numb)
{
int unic = numb.ToString().Distinct().ToArray().Length;
return unic;
}
public bool Finalcheck(bool simple, int numb)
{
if (simple)
{
string primeD = "";
string temp="";
string stringNumb = numb.ToString();
int count = 0;
bool checkDigit;
FillList(numb);
for (int i = 0; i < arraySimpleNumb.Count; i++)
{
checkDigit = true;
primeD = arraySimpleNumb[i];
for (int j = 0; j < stringNumb.Length; j++)
{
if (arraySimpleNumb[i].ToString().Contains(stringNumb[j]))
{
temp = arraySimpleNumb[i].ToString();
if (temp.Length != 1)
{
arraySimpleNumb[i] = temp.Remove(temp.IndexOf(stringNumb[j]),1);
}
}
else
{
checkDigit = false;
break;
}
}
if (checkDigit)
{
Console.WriteLine(" - " + primeD + " - ");
count++;
}
}
arraySimpleNumb.Clear();
if (stringNumb.Length != Factorial(UnicDigit(numb))&& UnicDigit(numb)!=1)
{
count--;
}
if (count == Factorial(UnicDigit(numb)))
{
return true;
}
return false;
}
else
{
return false;
}
}
}
}