Talk:Pandigital prime: Difference between revisions

m
→‎How about ...: μs, not ns
No edit summary
m (→‎How about ...: μs, not ns)
 
(5 intermediate revisions by 4 users not shown)
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} μs", x, sw.Elapsed.TotalMilliseconds * 1000); break;
bottom: ;
}
}
}</lang>
{{out}}
@ Tio.run:
<pre>76540231 41.4 μs</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.
 
:Good idea, assuming the authors of the existing solutions are OK with it (currently there are 11).--[[User:Tigerofdarkness|Tigerofdarkness]] ([[User talk:Tigerofdarkness|talk]]) 20:17, 10 September 2021 (UTC)
 
:Why not do both? As in: a pandigitial makes use of all the digits 1 to n, a pandigital0 uses all the digits 0 to n. Added a "with 0" section to the Phix entry, even with the full inner workings of both the output is still quite short. --[[User:Petelomax|Pete Lomax]] ([[User talk:Petelomax|talk]]) 10:00, 11 September 2021 (UTC)
 
:: Yeah, doing both seems a better idea to me and, if we make the '0' version optional, the existing solutions will still be valid. --[[User:PureFox|PureFox]] ([[User talk:PureFox|talk]]) 10:43, 11 September 2021 (UTC)
 
::OK, added the optional part, and removed my non-0 version. --[[User:Petelomax|Pete Lomax]] ([[User talk:Petelomax|talk]]) 12:33, 11 September 2021 (UTC)