Numbers with prime digits whose sum is 13: Difference between revisions

Content added Content deleted
m (→‎{{header|Pascal}}: comment modified)
m (→‎{{header|Pascal}}: unnessasary gblnominator...)
Line 716: Line 716:
MAXNUM = 113;
MAXNUM = 113;
var
var
gblPrimDgtCnt :tDigits;
gblPrimDgtCnt :tDigits;
gblCount: NativeUint;
gblCount: NativeUint;
gblNom :array [0..MAXNUM Div 2] of NativeUInt;


function isPrime(n: NativeUint):boolean;
function isPrime(n: NativeUint):boolean;
Line 741: Line 740:


procedure Sort(var t:tDigits);
procedure Sort(var t:tDigits);
// Sort descending to minimize * / in Calcpermcount
var
var
i,j,k: NativeUint;
i,j,k: NativeUint;
Line 766: Line 764:
//TempDgtCnt[0] = 3 and TempDgtCnt[1..3]= 2 -> dgtcnt = 3+3*2= 9
//TempDgtCnt[0] = 3 and TempDgtCnt[1..3]= 2 -> dgtcnt = 3+3*2= 9
//permcount = dgtcnt! /(TempDgtCnt[0]!*TempDgtCnt[1]!*TempDgtCnt[2]!*TempDgtCnt[3]!);
//permcount = dgtcnt! /(TempDgtCnt[0]!*TempDgtCnt[1]!*TempDgtCnt[2]!*TempDgtCnt[3]!);
//TempDgtCnt[0] = 3 and TempDgtCnt[1..3]= 2 -dgtcnt = 3+3*2= 9

//nom = 1,2,3, 4,5,6,7,8,9
//nom = 1,2,3, 4,5,6,7,8,9
//denom = 1,2,3, 1,2,1,2,1,2
//denom = 1,2,3, 1,2,1,2,1,2
var
var
pgblNom : ^NativeUInt;
TempDgtCnt : tdigits;
TempDgtCnt : tdigits;
i : NativeUint;
i,f : NativeUint;
begin
begin
TempDgtCnt := gblPrimDgtCnt;
TempDgtCnt := gblPrimDgtCnt;
Sort(TempDgtCnt);
Sort(TempDgtCnt);
pgblNom := @gblNom[1];
//jump over 1/1*2/2*3/3*4/4*..* TempDgtCnt[0]/TempDgtCnt[0]
//jump over 1/1*2/2*3/3*4/4*..* TempDgtCnt[0]/TempDgtCnt[0]
inc(pgblNom,TempDgtCnt[0]);
f := TempDgtCnt[0]+1;
result :=1;
result :=1;


For i := 1 to TempDgtCnt[1] do
For i := 1 to TempDgtCnt[1] do
Begin
Begin
result := (result*pgblNom^) DIV i;
result := (result*f) DIV i;
inc(pgblNom);
inc(f);
end;
end;
For i := 1 to TempDgtCnt[2] do
For i := 1 to TempDgtCnt[2] do
Begin
Begin
result := (result*pgblNom^) DIV i;
result := (result*f) DIV i;
inc(pgblNom);
inc(f);
end;
end;
For i := 1 to TempDgtCnt[3] do
For i := 1 to TempDgtCnt[3] do
Begin
Begin
result := (result*pgblNom^) DIV i;
result := (result*f) DIV i;
inc(pgblNom);
inc(f);
end;
end;
end;
end;
Line 826: Line 822:
BEGIN
BEGIN
writeln('Sum':6,'Count of arrangements':25);
writeln('Sum':6,'Count of arrangements':25);
// array for n! 1,2,3,4,5,6..n
gblNom[0]:= 1;
For i := 1 to High(gblNom) do
gblNom[i] := i;


Num := 1;
Num := 1;
Line 835: Line 827:
inc(num);
inc(num);
if Not(isPrime(Num)) then
if Not(isPrime(Num)) then
CONTINUE;
CONTINUE;
gblCount := 0;
gblCount := 0;
sum7 :=num;
sum7 :=num;