# Arup Guha # 4/13/2023 # Code to verify answer for COT 3100H Quiz 2 Problem 5 # Run Brute Force here def main(): ctr = go(5,5,1,"") print("count =",ctr) # a = # of A's left, b = # of B's left, c = # of c's left. def go(a,b,c,s): # Store # of solutions here. ctr = 0 # Got one, process it and return. if a == 0 and b == 0 and c == 0: print(s) ctr+=1 return ctr # We can always do three cases here. if len(s) == 0: ctr += go(a-1,b,c,s+"a") ctr += go(a,b-1,c,s+"b") ctr += go(a,b,c-1,s+"c") return ctr # Here we have to look at the previous character and frequencies # to decide what could go next. else: if a > 0 and s[-1] != 'a': ctr += go(a-1,b,c,s+"a") if b > 0 and s[-1] != 'b': ctr += go(a,b-1,c,s+"b") if c > 0 and s[-1] != 'c': ctr += go(a,b,c-1,s+"c") return ctr main()