Question: Trying to get permutations of letters of word

Hey there, I'm trying to count how many letter arrangements are possible by using the algorithm below (for Maple TA). It's a bit crude but the console tells me countcharacteroccurences second argument must be a string, but it works for the earlier letters. Can someone please give me a bit of guidance?

 

$temp = maple("
randomize();
with(MathML):
with(StringTools):
with(combinat):

rintS := rand(1..27);
word := ARITHMETIC,ALGORITHM,ASYMPTOTE,AVERAGE,CARTESIAN,CALCULUS,COEFFICIENT,COORDINATE,NUMERATOR,
DENOMINATOR,DIFFERENTIATE,DERIVATIVE,DIAMETER,DYNAMICS,EXTRAPOLATION,FACTORIALS,GEOMETRIC,
HYPOTENUSE,INTEGRATION,IRRATIONAL,INVERSE,ITERATION,POLYNOMIAL,COMBINATIONS,PERMUTATIONS,POLYGON;

disp := word[rintS()];
n := length(disp);

n1 := CountCharacterOccurrences(disp,A);
n2 := CountCharacterOccurrences(disp,B);
n3 := CountCharacterOccurrences(disp,C);
n4 := CountCharacterOccurrences(disp,D);
n5 := CountCharacterOccurrences(disp,E);
n6 := CountCharacterOccurrences(disp,F);
n7 := CountCharacterOccurrences(disp,G);
n8 := CountCharacterOccurrences(disp,H);
n9 := CountCharacterOccurrences(disp,I);
a1 := CountCharacterOccurrences(disp,J);
a2 := CountCharacterOccurrences(disp,K);
a3 := CountCharacterOccurrences(disp,L);
a4 := CountCharacterOccurrences(disp,M);
a5 := CountCharacterOccurrences(disp,N);
a6 := CountCharacterOccurrences(disp,O);
a7 := CountCharacterOccurrences(disp,P);
a8 := CountCharacterOccurrences(disp,Q);
a9 := CountCharacterOccurrences(disp,R);
b1 := CountCharacterOccurrences(disp,S);
b2 := CountCharacterOccurrences(disp,T);
b3 := CountCharacterOccurrences(disp,U);
b4 := CountCharacterOccurrences(disp,V);
b5 := CountCharacterOccurrences(disp,W);
b6 := CountCharacterOccurrences(disp,X);
b7 := CountCharacterOccurrences(disp,Y);
b8 := CountCharacterOccurrences(disp,Z);

z1 := n1!*n2!*n3!*n4!*n5!*n6!*n7!*n8!*n9!;
z2 := a1!*a2!*a3!*a4!*a5!*a6!*a7!*a8!*a9!;
z3 := b1!*b2!*b3!*b4!*b5!*b6!*b7!*b8!;
ans := n!/(z1*z2*z3);

Export(disp),convert(ans,string),convert(z1,string),convert(z2,string),convert(z3,string);
");

$ans = switch(1,$temp);
$disp = switch(0,$temp);

Please Wait...