If one accepts the axiom of choice, and assumes the prisoners each have the (unrealistic) ability to memorize an uncountably infinite amount of information and perform computations with uncountably infinite computational complexity, the answer is yes. In fact, even if we allow an uncountable number of different colors for the hats and an uncountable number of prisoners, the axiom of choice provides a solution that guarantees that only finitely many prisoners must die provided that each prisoner can see the hats of every other prisoner (not just those ahead of them in a line), or at least that each prisoner can see all but finitely many of the other hats. The solution for the two color case is as follows, and the solution for the uncountably infinite color case is essentially the same: