Talk:Pandigital prime: Difference between revisions

m
→‎How about ...: μs, not ns
m (→‎How about ...: μs, not ns)
 
(7 intermediate revisions by 4 users not shown)
Line 35:
 
::::::So, even if I still think than reusing he problem without any added value is a bit unfair, I’m now more forgiving. I suggest that we avoid Project Euler tasks if possible, except if we have some added value to offer. And that in any case, we refuse tasks which are not from the first hundred ones as it would be a clear violation of Project Euler rules. To be honest, this is only a policy position. You can solve any task without being a member and, so, are not committed to follow, even morally, Project Euler rules.
 
:::::::Hmm, I think plagiarism is equally immoral whether you are a member or not. --[[User:Petelomax|Pete Lomax]] ([[User talk:Petelomax|talk]]) 02:56, 6 September 2021 (UTC)
 
::::::For existing tasks, I finally propose to keep them. At least, the limits of what is acceptable are somewhat more clear.
Line 45 ⟶ 47:
::A "good" rosettacode task (usually) asks for implementation of a specific algorithm, with links to wikipedia/mathworld/oeis and some if not all expected results, whereas projecteuler is "solve this puzzle", with no algorithm and never any answer. The former encourages comparable submissions (the primary purpose of this site), and things that could (with due care) be re-used elsewhere, whereas the latter encourages highly divergent solutions and almost always non-reusable code.
::<small>(Obviously not every task submission is comparable on rc, but that is inevitable if you allow imperative/functional/declarative/stack-based/object-oriented and all the other programming paradigms.)</small>
::Not"Puzzles" are not a good fit, and it is clearly totally disrespectful to just dump them verbatim here. There is also a subtlety that I too missed on first reading:
::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)