Combine two numbers into one and extract them back

1.4k Views Asked by At

I have two numbers(A,B), I want to combine the numbers into one(C)

The constraints are

  1. A's range = 0 to 3 (4 values)

  2. B's range = 0 to 900 (900 values)

  3. C must have a maximum of 3 digits only.

Example:

Input: A=2, B=635

Calculate C, lets say C = 2 + 635 = 637 (only 3 digits)

Given C = 637, Extract A = 2 & B = 635.

===============

A's range is fixed at 4.

B's range can be reduced from 900, but cannot go below 500.

C MUST be 3 digits only

1

There are 1 best solutions below

4
On

If $C$ has a maximum of $3$ digits, then it's impossible. There are only $1000$ possibilities ($1999$ if it can be negative), but it would need to cover $4\cdot 900=3600$ different combinations of $A$ and $B$. There just isn't room.

If you allow four digits, then $C=1000A+B$ works.