Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Prisoner B would write the number 13345110110099 where the first 11 digits, 13,345,110,110 = 1,000,000,000 + 12,345,110,110 and the last three digits are prisoner B's number, 099. You then take 13,345,110,110 - (1,011,012,345,110 - 11,012,345) = 12,345,110,110 which is the number on your hat.
If a person's number is "110", then there are at least 110 prisoners. Let us assume that there are less than 1000. Let us further assume that the other prisoners, besides prisoners A and B, have a total sum of 1,000,000,000 on their hats. We will assume that prisoner B is number "099." Then, prisoner A would write the number 1011012345110 where the first 10 digits, 1,011,012,345,110 = 1,000,000,000 + 11,012,345 and the last three digits are prisoner A's number, "110."
I did it using the algorithm in the explanation. I put the numbers in Excel, got a sum of each row and column. Since there's one number different in each row/column, the intersection of the rows and columns that have the same sum must be the numbers that were changed. I then just picked the numbers that would make the sums correct.