Talk:Pandigital prime: Difference between revisions

proposed altering the task description
No edit summary
(proposed altering the task description)
Line 50:
::That page grants some permission to publish a solution, but in no way expresses permission to ask for other solutions on a different site.
::The only exception would/might be to further explore some clearly specified approach. --[[User:Petelomax|Pete Lomax]] ([[User talk:Petelomax|talk]]) 02:30, 6 September 2021 (UTC)
 
 
== How about ... ==
... altering the task description to include zero? This gives it a different answer. Here is a proposed solution in '''C#''':
<lang csharp>using System;
class Program {
// Find the highest pandigital number in base 10 (including the digit zero)
// Since the sum-of-digits of the pandigital numbers 0..9 and 0..8 are respectively 45 and 36, (both
// divisible by 3 and therefore always composite), we will only be looking at pandigital numbers 0..7
static void Main(string[] args) {
var sw = System.Diagnostics.Stopwatch.StartNew();
// The difference between every permutation is a multiple of 9. To check odds only, start at XXXXXX01
// and decrement by 18. It's slightly faster to check pan-digitality before the multi-factor test.
for (int x = 76543201; ; x -= 18) {
// Tests for pan-digitality of x
// Hard-coded to only check for digits 0 through 7. If a duplicate occurs, at least one of the
// other required digits 0..7 will be missing, and therefore rejected.
var s = x.ToString();
for (var ch = '0'; ch < '8'; ch++) if (s.IndexOf(ch) < 0) goto bottom;
// 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 bottom;
if (x % (i += 2) == 0) goto bottom;
}
sw.Stop(); Console.Write("{0} {1} ns", x, sw.Elapsed.TotalMilliseconds * 1000); break;
bottom: ;
}
}
}</lang>
{{out}}
@ Tio.run:
<pre>76540231 41.4 ns</pre>--[[User:Enter your username|Enter your username]] ([[User talk:Enter your username|talk]]) 16:48, 10 September 2021 (UTC)
P.S. The task description would have to be altered to give the example of the 0..4 pandigital as follows:
 
::Task
::The following problem is inspired by Project Euler problem 41.
 
::We shall say that an 0..n number is pandigital if it makes use of all the digits 0 to n exactly once. For example, 43201 is a 0..4 pandigital and is also prime.
 
::What is the largest 0..n pandigital prime that exists?
 
::Assume that the problem is talking about decimal numbers.
 
The goofy thing is that the highest odd 0..4 pandigital number is also prime, so not much of a search is needed for 0..4 pandigital. This may be why P.E. didn't include the zero in their problem.