Multi-base primes: Difference between revisions
m
syntax highlighting fixup automation
Thundergnat (talk | contribs) m (Promote. multiple implementations, little controversy) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 48:
Originally translated from [[#Wren|Wren]] with ideas borrowed from other solutions.
The maximum base and number of characters can be specified as command line arguments.
<
#include <cmath>
#include <cstdint>
Line 173:
multi_base_primes(max_base, max_length);
return EXIT_SUCCESS;
}</
{{out}}
Line 224:
=={{header|F_Sharp|F#}}==
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)]
<
// Multi-base primes. Nigel Galloway: July 4th., 2021
let digits="0123456789abcdefghijklmnopqrstuvwxyz"
Line 232:
i|>Seq.iter(fun(n,g)->printf " %s->" (n|>List.map(fun n->digits.[n])|>Array.ofList|>System.String)
g|>Seq.iter(fun(g,_)->printf "%d " g); printfn ""); printfn "")
</syntaxhighlight>
{{out}}
<pre>
Line 252:
=={{header|Factor}}==
{{works with|Factor|0.99 2021-06-02}}
<
math.functions math.parser math.primes math.ranges present
sequences ;
Line 272:
[ dup (bases) filter "%d => %[%d, %]\n" printf ] each ;
4 [1,b] [ multibase. nl ] each</
{{out}}
<pre>
Line 295:
{{libheader|Go-rcu}}
This takes about 1.2 seconds and 31.3 seconds to process up to 5 and 6 character strings, respectively.
<
import (
Line 391:
fmt.Println()
}
}</
{{out}}
Line 439:
=={{header|Julia}}==
<
function maxprimebases(ndig, maxbase)
Line 467:
maxprimebases(n, 36)
end
</
<pre>
The maximum number of prime valued bases for base 10 numeric strings of length 1 is 34. The base 10 value list of this is:
Line 493:
=== Up to base 62 ===
<
function maxprimebases(ndig, maxbase)
Line 527:
maxprimebases(n, 62)
end
</
<pre>
The maximum number of prime valued bases for base up to 36 numeric strings of length 1 is 34. The value list of this is:
Line 566:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
OtherBasePrimes[n_Integer] := Module[{digs, minbase, bases},
digs = IntegerDigits[n];
Line 585:
OtherBasePrimesPower[3] // Column
OtherBasePrimesPower[4] // Column
OtherBasePrimesPower[5] // Column</
{{out}}
<pre>{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}}
Line 607:
<
const
Line 674:
for m in ctx.maxStrings:
echo m.indices.mapIt(Digits[it]).join(), " → ", m[1].join(" ")
echo()</
{{out}}
Line 701:
First counting the bases that convert a MAXBASE string of n into a prime number.<BR>
Afterwards only checking the maxcount for the used bases.<BR>
<
{$IFDEF FPC}
{$MODE DELPHI}
Line 1,031:
writeln(' Converting ',(GetTickCount64-T0)/1000:6:3,' s');
{$IFDEF WINDOWS} readln; {$ENDIF}
end.</
{{out}}
<pre>
Line 1,094:
{{trans|Raku}}
{{libheader|ntheory}}
<
use warnings;
use feature 'say';
Line 1,122:
}
say ''
}</
{{out}}
<pre>1 character strings that are prime in maximum bases: 34
Line 1,144:
=={{header|Phix}}==
Originally translated from Rust, but changed to a much fuller range of digits, as per talk page.
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">maxbase</span><span style="color: #0000FF;">=</span><span style="color: #000000;">36</span> <span style="color: #000080;font-style:italic;">-- or 62</span>
Line 1,222:
<span style="color: #000000;">max_prime_bases</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">maxbase</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</
{{out}}
<pre>
Line 1,276:
''All your base are belong to us. You have no chance to survive make your prime.''
<syntaxhighlight lang="raku"
my $sieve = Math::Primesieve.new;
Line 1,298:
.say for %prime-base.grep( +*.value.elems == $e ).grep(*.key.chars == $m).sort: *.key;
say '';
}</
{{out}}
Line 1,322:
You can't really assume that the maximum string will be all numeric digits. It is just an accident that they happen to work out that way with a upper limit of base 36. If we do the same filtering using a maximum of base 62, we end up with several that contain alphabetics.
<syntaxhighlight lang="raku"
use Base::Any;
Line 1,345:
.say for %prime-base.grep( +*.value.elems == $e ).grep(*.key.chars == $m).sort: *.key;
say '';
}</
{{out|Yields}}
<pre>1 character strings that are prime in maximum bases: 60
Line 1,362:
=={{header|REXX}}==
<
parse arg widths . /*obtain optional argument from the CL.*/
if widths=='' | widths=="," then widths= 5 /*Not specified? Then use the default.*/
Line 1,405:
end /*k*/ /* [↑] only process numbers ≤ √ J */
#= # + 1; @.#= j; sq.#= j*j /*bump # Ps; assign next P; P squared.*/
end /*j*/; return</
{{out|output|text= when using the default input:}}
<pre>
Line 1,433:
=={{header|Rust}}==
{{trans|Julia}}
<
// primal = "0.3"
Line 1,484:
max_prime_bases(n, 36);
}
}</
{{out}}
Line 1,513:
===Up to base 62===
{{trans|C++}}
<
// primal = "0.3"
Line 1,629:
println!("elapsed time: {} milliseconds", time.as_millis());
}
}</
{{out}}
Line 1,683:
=={{header|Sidef}}==
{{trans|Julia}}
<
var maxprimebases = [[]]
Line 1,711:
for n in (1..5) {
max_prime_bases(n)
}</
{{out}}
<pre>
Line 1,737:
{{libheader|Wren-fmt}}
This takes about 1.6 seconds to process up to 4 character strings and 58 seconds for the extra credit which is not too bad for the Wren interpreter.
<
var maxDepth = 5
Line 1,793:
printResults.call()
System.print()
}</
{{out}}
|