0

hi,
i want permutation for all alphabets with word length is 8.but i get only permutation for 4.pls help me to debug this issue

code:

<?PHP

FUNCTION permutations($letters,$num){ 
$last = STR_REPEAT($letters{0},$num); 
$result = ARRAY(); 
WHILE($last != STR_REPEAT(lastchar($letters),$num)){ 
echo "$last";
$result[] = $last; 
$last = char_add($letters,$last,$num-1); 
} 
$result[] = $last; 
RETURN $result; 
} 
FUNCTION char_add($digits,$string,$char){ 
IF($string{$char} <> lastchar($digits)){ 
$string{$char} = $digits{STRPOS($digits,$string{$char})+1}; 
RETURN $string; 
}ELSE{ 
$string = changeall($string,$digits{0},$char); 
RETURN char_add($digits,$string,$char-1); 
} 
} 
FUNCTION lastchar($string){ 
RETURN $string{STRLEN($string)-1}; 
} 
FUNCTION changeall($string,$char,$start = 0,$end = 0){ 
IF($end == 0) $end = STRLEN($string)-1; 
FOR($i=$start;$i<=$end;$i++){ 
$string{$i} = $char; 
} 
RETURN $string; 
} 
?> 




<?php
for($j=1;$j<9;$j++){
$Array=permutations("ABCDEFGHIJKLMNOPQRSTUVWXYZ",$j); 
FOR($i=0 ; $i < COUNT($Array) ; $i++) { 
ECHO "$i." . $Array[$i] . "<BR>"; 
} 
}
?> 

output:

i want a output like this
a
b
c
d
e
f
.
.
.
.
.
z
aa
ab
ac
ad
.
.
.
.
.
.
az
.
.
.
.
.
.
.
.
.
.
zzzzzzzz

But the above code shown like this
a
b
c
d
.
.
.
.
.
aa
ab
ac
.
.
.
.
az
.
.
.
zzzz

yes

Edited by saranya@123

2
Contributors
1
Reply
10
Views
3 Years
Discussion Span
Last Post by pritaeas
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.