public class Main21 {
static int count=0;
public static void printer(String s, int n, int sz){
if(n>sz-1)
return;
String s1=s+"P";
String s2=s+"A";
String s3=s+"L";
if(s1.length() == sz && s2.length() == sz && s3.length() == sz){
if( !s1.contains("AA") && !s1.contains("LLL") && !s2.contains("AA") && !s2.contains("LLL") && !s3.contains("AA") && !s3.contains("LLL") )
{
System.out.print(s1+" "+s2+" "+s3+" ");
count++;
}
}
printer(s1,n+1,sz);
printer(s2,n+1,sz);
printer(s3,n+1,sz);
}
public static void main(String[] args) {
int sz=2 ;
printer("P",1,sz);
printer("A",1,sz);
printer("L",1,sz);
System.out.println("\n"+count*3);
}
}
I am getting result: PP PA PL LP LA LL 6
AL and AP is getting missed. But when I am passing size as 3 its working fine. Could you please point out the fault?
When passed 3:
PPP PPA PPL PLP PLA PLL APP APA APL ALP ALA ALL LPP LPA LPL 15
sends inAthens2.contains("AA")will be true, which prevents the print.