Pandigital prime: Difference between revisions

→‎{{header|C#|CSharp}}: modified for 1..7 / 0..7
m (added a Prime Numbers category.)
(→‎{{header|C#|CSharp}}: modified for 1..7 / 0..7)
Line 137:
=={{header|C#|CSharp}}==
<lang csharp>using System;
 
class Program {
// Find the highest pandigital number in base 10, (withoutexcluding or including the digit zero).
 
// Since the sum-of-digits of the pandigital numbers 10..9 and 10..8 are respectively 45 and 36, (both
// divisible by 3 and therefore always composite), we will only be looking at pandigital numbers 10..7
 
static void Mainfun(string[]char argssp) {
var sw = System.Diagnostics.Stopwatch.StartNew();
// The difference between every permutation is a multiple of 9. To check odds only, start at XXXXXX1
// start at XXXXXX1 or XXXXXX01 and decrement by 18.
// and decrement by 18. It's slightly faster to check pan-digitality before the multi-factor test.
 
for (int x = sp == '1' ? 7654321 : 76543201; ; x -= 18) {
 
// Tests for pan-digitality of x
// Hard-coded to only checkCheck for digits 1sp through 7. If a duplicate occurs, at least one of the
// other required digits 1sp..7 will be missing, and therefore rejected.
var s = x.ToString();
for (var ch = '1'sp; ch < '8'; ch++) if (s.IndexOf(ch) < 0) goto bottomnxt;
 
// Multi-factor test
// There is no check for even numbers since starting on an odd number and stepping by an even number
if (x % 3 == 0) continue;
for (int i = 1; i * i < x; ) {
if (x % (i += 4) == 0) goto bottomnxt;
if (x % (i += 2) == 0) goto bottomnxt;
}
sw.Stop(); Console.WriteWriteLine("{0}..7: {1,10:n0} {2} ns", sp, x, sw.Elapsed.TotalMilliseconds * 1000); break;
bottomnxt: ;
}
}
 
static void Main(string[] args) {
fun('1');
fun('0');
}
}</lang>
{{out}}|Output @ Tio.run:}}
<pre>7652413 291.2.7: 7,652,413 21 ns</pre>
0..7: 76,540,231 24.5 ns</pre>
 
=={{header|Factor}}==