My goal is to solve the USACO necklace problem. I try to use a yield function to return the red_num and blue_num to 0 my final_calculation is smaller than red_num or applying to else function. Input: 29 wwwbbrwrbrbrrbrbrwrwwrbwrwrrb Output(Expected): 5
However my code show False when I running the yield and return. I had iterate my function and pass it through a generator, what did I do wrong.
def calculation(letter):
final_calculation =final_calculation_b=0
red_num = 0
blue_num = 0
while True:
for i in range(read_line - 1):
z = i + 1
if letter[i] == "r":
red_num += 1
if (letter[z] == "w"):
red_num += 1
else:
if letter[z] == "b":
if final_calculation <= max(red_num, final_calculation):
final_calculation = max(red_num, final_calculation)
yield red_num == 0
return final_calculation
else:
return red_num==0
elif letter[i] == "b":
blue_num += 1
if letter[z] == "w":
blue_num += 1
else:
if letter[z] == "a":
if final_calculation_b <= max(blue_num, final_calculation):
final_calculation_b = max(blue_num, final_calculation)
yield blue_num==0
return final_calculation_b
else:
return blue_num==0
else:
red_num += 1
blue_num += 1
if final_calculation > final_calculation_b:
return final_calculation
else:
return final_calculation_b