# Find the Two Item Amounts

I bought 2 items yesterday and the receipt was incorrect, so I asked the cashier about it.

She told me that

1. The receipt printer had been acting funny recently.
2. The total is always correct, but some of the lines from the item amounts are randomly removed. For example, the 1 in the first item amount on the receipt below could be a 1,3,4,7,8, or 9 (not zero because zero is never shown as a leading digit).
3. It always removes the same number of lines from each item amount (not each digit).

How much did I pay for each item?

The accepted answer will articulate all logic steps.

Here is the receipt: The correct amounts are

723.98 and 898.80 which equal 1622.78

Starting from the right:

As there can be no 'carry over' for the right most digit, the 5 + 0 must equal 8 (or 18).

5 can be 5, 6, 8 or 9, whereas 0 can be 0 or 8. The only combination here that makes 8, is 8 + 0. This is 2 lines removed from the first amount, and 0 from the second.

Continuing left:

There is no carry over from 8 + 0, so we need 4 + 9 to equal 7 (or 17).

4 can be 4, 8 or 9, and 9 can be 8 or 9. To make 7, we have 8 + 9 or 9 + 8 to make 17. We will come back to get the right order later using rule 3.

Third from the right:

There is a carry over, so we need 3 + 8 to make 1 (or 11). This is already made - and as 8 can only be an 8 this column is untouched. 3 + 8 will make 11.

The second column:

Again there is a carry over, so we need 2 + 7 to make 1 (or 11).

2 can be 2 or 8, and 7 can be 0, 3, 7, 8 or 9. The combinations that make 1 are 2 + 9 and 8 + 3 to make 11. We will come back to find out which one.

There is a carry over, and we also know we need to create a carry over, so we need 1 + 6 to make 15.

1 can be 1, 3, 4, 7, 8 or 9, and 6 can be 6 or 8. The combinations that make 15 are 7 + 8 or 9 + 6. We will again come back to find out which one.

Using rule 3 to get the final amounts:

We have 2 + (2/3) + 0 + (0/2) + (1/4) = 5, 6, 7, 8, 9 or 10 lines removed from the first amount.
And also 0 + (0/1) + 0 + (2/3) + (0/1) = 2, 3, 4, or 5 lines removed from the second amount.

As 5 lines is the only intersect, from rule 3 there must be 5 removed from each amount, making the undecided combinations 9 + 8, 2 + 9 and 7+8.

So the final sum is

723.98 + 898.80 = 1622.78

• In the second column, 2 can be 2 or 8 (not 9) allowing 8 + 3 = 11 Jun 19 at 17:44
• @DanielMathias d'oh, good spot! Fixed - doesn't change the answer - but makes the combinations of lines removed much more satisfying! Jun 19 at 17:54

723.98 + 898.80 = 1,622.78

Starting from the right:

5 maps to 5,6,8,9; 0 maps to 8,0. The only combination there that adds to 8 (or 18) is 0,8. My initial guess was 5 > 8, leaving 8+0=8 in the hundredths place. 2 extra lines on top.

Next space:

To get seven in the tenths place, we need 7 or 17. 4 maps to 4,8,9; 8 maps to 8,9. Only 8 and 9 make 17, so I tried 4 > 9, 9 > 8, making 4 lines added on top, 1 line added on bottom.

Next:

In the ones, we need 2, which since the tenths had a 1 to carry over, 1 + 3 + 8 makes 12, giving the 2 we need, and no combination of changes to digits is still valid, so leave those. 4,1 lines added

Next:

With the 1 carried from the 12, we have 1 + 2 + 7 = 9, and we need a 2. There's no way to convert to 02, since if the 7 > 0 we'd have 3, so 7 > 9 to make 1 + 2 + 9 = 12. lines added: 4/4

Finally:

with the carried 1, we have 1 + 1 + 6 = 16, so we obviously need a change. Either 9+6 or 8+7 will make the 15+1 we need to get 16, and 9+6 would mean 4 lines on top and 0 on bottom, leaving 7/4 lines, which breaks the rules. 8+7 however makes the lines out to be 5/5, satisfying all constraints.

That leaves the final solution as:


_   _   _    _   _
|  _|  _|  |_| |_|
| |_   _| . _| |_|
_   _   _    _   _
|_| |_| |_|  |_| | |
+ |_|  _| |_| .|_| |_|
---------------------
_   _   _    _   _
| |_   _|  _|    | |_|
| |_| |_  |_  .  | |_|

This is a quick visualisation of removing lines from 8, top to bottom: Number on the edges are how many lines are removed. Let's note, that when we are adding two numbers the carry over can only be one or zero. Based on that and on the graph we can build the following table with all possible combinations of the top and bottom rows:


Top item candidates:    987|228|3|898|8
Bottom item candidates: 688|903|8|889|0
---+---+-+---+-

The five blocks are the five digits in the line items. The very first row can sum up only to 16 or 15, and the only three ways to do that is 9/6, 8/8 and 7/8, and similar for the rest of the rows. It's easy to see that the maximum number of lines at the bottom adds up to 5, which is also the minimum number of lines the top adds up to. There are only one way at the top that adds 5 lines, by the number of added lines it's 1/0/0/2/2 and by the item digits it's 7/2/3/9/8. These correspond to two ways at the bottom, where the ambiguity in the second from the left position, so our two numbers are 723.98 and 8x8.80, where x is either 0 or 9. By summing up those two numbers we see that it is 9, not 0 and the final answer is 723.98 + 898.80