<?php
function
fact(
$n
)
{
$f
= 1;
for
(
$i
= 2;
$i
<=
$n
;
$i
++)
{
$f
=
$f
*
$i
;
}
return
$f
;
}
function
npr(
$n
,
$r
)
{
return
fact(
$n
) / fact(
$n
-
$r
);
}
function
countPermutations(
$str
)
{
$even
=
floor
(
strlen
(
$str
)/ 2);
$odd
=
strlen
(
$str
) -
$even
;
$ways
= 0;
$freq
=
array_fill
(0, 26, 0);
for
(
$i
= 0;
$i
<
strlen
(
$str
);
$i
++)
{
++
$freq
[ord(
$str
[
$i
]) - ord(
'a'
)];
}
$nvowels
=
$freq
[0] +
$freq
[4] +
$freq
[8] +
$freq
[14] +
$freq
[20];
$nconsonants
=
strlen
(
$str
) -
$nvowels
;
$ways
= npr(
$odd
,
$nvowels
) *
npr(
$nconsonants
,
$nconsonants
);
return
$ways
;
}
$str
=
"geeks"
;
echo
countPermutations(
$str
);
?>