Multi-base primes: Difference between revisions
Content added Content deleted
(→{{header|Pascal}}: inserted pascal version) |
(Realize in F#) |
||
Line 198: | Line 198: | ||
</pre> |
</pre> |
||
=={{header|F_Sharp|F#}}== |
|||
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)] |
|||
<lang fsharp> |
|||
// Multi-base primes. Nigel Galloway: July 4th., 2021 |
|||
let digits="0123456789abcdefghijklmnopqrstuvwxyz" |
|||
let fG n g=let rec fN g=function i when i<n->i::g |i->fN((i%n)::g)(i/n) in primes32()|>Seq.skipWhile((>)(pown n (g-1)))|>Seq.takeWhile((>)(pown n g))|>Seq.map(fun g->(n,fN [] g)) |
|||
let fN g={2..36}|>Seq.collect(fun n->fG n g)|>Seq.groupBy snd|>Seq.groupBy(snd>>(Seq.length))|>Seq.maxBy fst |
|||
{1..4}|>Seq.iter(fun g->let n,i=fN g in printfn "The following strings of length %d represent primes in the maximum number of bases(%d):" g n |
|||
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 "") |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
The following strings of length 1 represent primes in the maximum number of bases(34): |
|||
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 |
|||
The following strings of length 2 represent primes in the maximum number of bases(18): |
|||
21->3 5 6 8 9 11 14 15 18 20 21 23 26 29 30 33 35 36 |
|||
The following strings of length 3 represent primes in the maximum number of bases(18): |
|||
131->4 5 7 8 9 10 12 14 15 18 19 20 23 25 27 29 30 34 |
|||
551->6 7 11 13 14 15 16 17 19 21 22 24 25 26 30 32 35 36 |
|||
737->8 9 11 12 13 15 16 17 19 22 23 24 25 26 29 30 31 36 |
|||
The following strings of length 4 represent primes in the maximum number of bases(19): |
|||
1727->8 9 11 12 13 15 16 17 19 20 22 23 24 26 27 29 31 33 36 |
|||
5347->8 9 10 11 12 13 16 18 19 22 24 25 26 30 31 32 33 34 36 |
|||
</pre> |
|||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
{{works with|Factor|0.99 2021-06-02}} |
{{works with|Factor|0.99 2021-06-02}} |