Pan base non-primes: Difference between revisions

Add Mathematica/Wolfram Language implementation
(Added Easylang)
(Add Mathematica/Wolfram Language implementation)
Line 680:
Odd up to and including 2500: 161//953, or 16.89%.
Even up to and including 2500: 792//953, or 83.1%.
</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
{{trans|Julia}}
<syntaxhighlight lang="Mathematica">(* Define the function to check if a number is a pan base composite *)
IsPanBaseComposite[n_] := Module[
{d = IntegerDigits[n], bases, compositeInAllBases},
bases = Range[Max[d] + 1, Max[10, n]];
compositeInAllBases = Not /@ PrimeQ[FromDigits[d, #] & /@ bases];
AllTrue[compositeInAllBases, Identity]
]
 
(* Generate the list of all pan base composites up to 2500 *)
panBase2500 = Select[Range[2, 2500], IsPanBaseComposite]
 
(* Filter out the odd numbers from the pan base composites *)
oddPanBase2500 = Select[panBase2500, OddQ]
 
(* Calculate the ratio of odd pan base composites to all pan base composites *)
ratio = Length[oddPanBase2500] / Length[panBase2500]
 
(* Print the first 50 pan base non-primes *)
Print["First 50 pan base non-primes:"]
Print[StringJoin[Riffle[ToString /@ Take[panBase2500, 50], ", "]]]
 
(* Print the first 20 odd pan base non-primes *)
Print["\nFirst 20 odd pan base non-primes:"]
Print[StringJoin[Riffle[ToString /@ Take[oddPanBase2500, 20], ", "]]]
 
(* Print the count of pan-base composites up to and including 2500 *)
Print["\nCount of pan-base composites up to and including 2500: ", Length[panBase2500]]
 
(* Print the ratios *)
Print["Odd up to and including 2500: ", Rationalize[ratio], ", or ", N[ratio * 100, 4], "%."]
Print["Even up to and including 2500: ", Rationalize[1 - ratio], ", or ", N[(1 - ratio) * 100, 4], "%."]</syntaxhighlight>
{{out}}
<pre>
First 50 pan base non-primes:
4, 6, 8, 9, 20, 22, 24, 26, 28, 30, 33, 36, 39, 40, 42, 44, 46, 48, 50, 55, 60, 62, 63, 64, 66, 68, 69, 70, 77, 80, 82, 84, 86, 88, 90, 93, 96, 99, 100, 110, 112, 114, 116, 118, 120, 121, 130, 132, 134, 136
 
First 20 odd pan base non-primes:
9, 33, 39, 55, 63, 69, 77, 93, 99, 121, 143, 165, 169, 187, 231, 253, 273, 275, 297, 299
 
Count of pan-base composites up to and including 2500: 953
Odd up to and including 2500: 161/953, or 16.894018887722980063`4.%.
Even up to and including 2500: 792/953, or 83.105981112277019937`4.%.
</pre>
 
337

edits