You can guarantee that 10 will be freed. The prisoners chat the night before and agree on the following. The prisoner on the back of the line tells everybody the color of the hat immediately in front of him. So prisoner #20 says, "red". Now prisoner #19 knows his hat is red. He in turn says, "red" and is freed. Prisoner #18 sees that #17 is wearing black. So he says, "black". Now #17 says "black" and is freed. #16 does this favor for #15. #14 does this for #13 and so on.