Back
Close

Holey Times

Statement

 Goal

You have to fill in all the unknown digits in a multiplication.
These unknown digits are marked as stars * in the operation.
Note that the numbers involved never begin with a zero, excepted when a line is null.
* For example, 234 is possible everywhere.
* 00 is accepted but only as a full line in a partial result.
* 0234 is not possible, neither as operand, partial result or result.

The multiplication symbol is an x.
The stars may appear everywhere in the operation:
* In the operands, in the partial results or in the result.
* In only one of the three, in two or three of them.

In the partial results, the first line has got no trailing zeroes (but might end by zero if you multiply 5×48). The second line has got one trailing zero, the second line has got two trailing zeroes, and so on. Why?
Because if you calculate 907×757, in fact, the operation is shown as 907×(7+50+700)=907×7 [first line] + 907×50 [second line] + 907×700 [third line]. Thus, the operation must be shown as:
   907
x 757
------
6349 → 7×907
45350 → 50×907
634900 → 700×907
------
686599

And not as:
   907
x 757
------
6350 → 50×907
45349 → 7×907
634900 → 700×907
------
686599
Input
Line 1: The number n of lines of the operation
Next n lines: The holey multiplication
Output
Write the input but with the stars replaced with digits.
No star shall be left.
Constraints
There is only one solution.
Example
Input
6
  25
x  *
----
 175
----
 175
Output
  25
x  7
----
 175
----
 175

Tags
ArithmeticRegular expressionsAscii Art

Difficulty
Medium

Test cases
One missing digit in the operand Test
Input
6 25 x * ---- 175 ---- 175
Output
25 x 7 ---- 175 ---- 175

One missing digit in the operand Validator
Input
6 45 x * ---- 405 ---- 405
Output
45 x 9 ---- 405 ---- 405

Missing digits in the operands Test
Input
7 ** x ** ---- 534 890 ---- 1424
Output
89 x 16 ---- 534 890 ---- 1424

Missing digits in the operands Validator
Input
7 **8 x ** ---- 1424 3560 ---- 4984
Output
178 x 28 ---- 1424 3560 ---- 4984

Missing digits in the partial results Test
Input
7 145 x 57 ---- **** **** ---- 8265
Output
145 x 57 ---- 1015 7250 ---- 8265

Missing digits in the partial results Validator
Input
7 789 x 36 ----- **** ***** ----- 28404
Output
789 x 36 ----- 4734 23670 ----- 28404

Missing digits in the result Test
Input
8 1478 x 125 ------ 7390 29560 147800 ------ ******
Output
1478 x 125 ------ 7390 29560 147800 ------ 184750

Missing digits in the result Validator
Input
8 1478 x 125 ------ 7390 29560 147800 ------ ******
Output
1478 x 125 ------ 7390 29560 147800 ------ 184750

Missing digits everywhere Test
Input
7 **9 x 8* ----- 2**6 **3** ----- 5283*
Output
629 x 84 ----- 2516 50320 ----- 52836

Missing digits everywhere Validator
Input
7 3**8 x *9 ------ 3*2** 14312* ------ 1*5*2*
Output
3578 x 49 ------ 32202 143120 ------ 175322

No leading zeros Test
Input
8 *** x **7 ------ ***1 2***0 ***200 ------ 24*151
Output
543 x 457 ------ 3801 27150 217200 ------ 248151

No leading zeros Validator
Input
7 *** x ** ----- 2*9* ***0 ----- 1147*
Output
459 x 25 ----- 2295 9180 ----- 11475

Mind the hole Test
Input
8 ** x 7*5 ----- 415 ** 58100 ----- *****
Output
83 x 705 ----- 415 00 58100 ----- 58515

Mind the hole Validator
Input
7 *** x 1* ---- * **** ---- 8960
Output
896 x 10 ---- 0 8960 ---- 8960

The tough one Test
Input
8 *** x *** ------ **** ***** ****** ------ 686599
Output
907 x 757 ------ 6349 45350 634900 ------ 686599

The tough one Validator
Input
8 *** x *** ------ **** ** ****** ------ 686599
Output
757 x 907 ------ 5299 00 681300 ------ 686599

Solution language

Solution

Stub generator input