Statistics

Problem Statement for "BaseMystery"

Problem Statement

The base of a number system is the number of different values each digit can represent. For example, in base-2 (binary), there are 2 values each digit can take: 0 and 1. In base-10, a digit can take values 0 through 9, inclusive. Sometimes, it is difficult to determine which base a numerical expression is in. An equation is valid for a given base if all of the digits are less than the base, and the numerical meaning of the equation is correct. For example, "1+1=10" for base-10 satisfies the rule that the digits are all less than 10, but 1+1 = 2 in base-10, so the equation is not correct for base-10.

If we assume that the characters '0'-'9' represent the values 0 - 9, and the characters 'A'-'J' represent the values 10 - 19, then we can represent numbers with a base up to 20. The equation will be in the following form:

<num>+<num>=<num>

Where each <num> is a String consisting of characters '0'-'9' and 'A'-'J', which does not have any extra leading zeros, and is at most 5 digits long.

Given an equation as defined above, you should return which bases in the range of 2 to 20, inclusive, are valid for the equation. Return the bases in a int[] in ascending order.

Definition

Class:
BaseMystery
Method:
getBase
Parameters:
String
Returns:
int[]
Method signature:
int[] getBase(String equation)
(be sure your method is public)

Constraints

  • equation will be of the form "+="
  • Each in equation will have between 1 and 5 characters, inclusive.
  • Each in equation will consist only of numeric digits '0' - '9' and capital letters 'A' - 'J', and will not have extra leading zeros.

Examples

  1. "1+1=2"

    Returns: { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }

    The only base which this does not work for is base-2. In base 2, 2 is represented by "10"

  2. "1+1=10"

    Returns: { 2 }

    The same equation valid for base 2.

  3. "1+1=3"

    Returns: { }

    1+1 is never 3, no matter what base you are in.

  4. "ABCD+211=B000"

    Returns: { 14 }

    In base-14, the digits are 0-9, A-D. Adding one to the ones column yields 10 base-14, which carries over to make the 10's column a 'D'. Adding 1 to that column yields 10 again, which carries and makes the 100's column a 'C'. Adding 2 to C yields 10 again, which adds 1 to the 1000's column, resulting in B000.

  5. "ABCD+322=B000"

    Returns: { 15 }

    For base-15, we have increased the number required to wrap to 0 by 1.

  6. "1+0=1"

    Returns: { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }

    This is valid for all bases.

  7. "GHIJ+1111=HJ00"

    Returns: { 20 }

  8. "1234+8765=9999"

    Returns: { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }

  9. "1234+8766=10000"

    Returns: { 10 }

  10. "JJJJ+JJJJ=1JJJI"

    Returns: { 20 }

  11. "A9A9A+9A9A9=JJJJJ"

    Returns: { 20 }

  12. "I63+81G=1780"

    Returns: { 19 }

  13. "28H77+E8=7D37C"

    Returns: { }

  14. "E8+CDJE=CEE2"

    Returns: { 20 }

  15. "9+4FAIH=4FAJ6"

    Returns: { 20 }

  16. "F4+AH1=BC5"

    Returns: { 20 }

  17. "JB+11H9=F9F"

    Returns: { }

  18. "4CCF+4=4CD0"

    Returns: { 19 }

  19. "6+I3=I9"

    Returns: { 19, 20 }

  20. "6F+I=7D"

    Returns: { 20 }

  21. "8+A78=A85"

    Returns: { 11 }

  22. "JI+A14=EDGD"

    Returns: { }

  23. "26C+G20EA=G2323"

    Returns: { 19 }

  24. "7B+I23E3=I242E"

    Returns: { 19 }

  25. "I0HE+6=I0I1"

    Returns: { 19 }

  26. "9+D82=D8B"

    Returns: { 14, 15, 16, 17, 18, 19, 20 }

  27. "5+5499=549E"

    Returns: { 15, 16, 17, 18, 19, 20 }

  28. "3+1=4"

    Returns: { 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }

  29. "94529+58=94581"

    Returns: { 16 }

  30. "E+3D8=2J1A3"

    Returns: { }

  31. "BE+7FB=875"

    Returns: { 20 }

  32. "BI2B2+3I7DJ=2"

    Returns: { }

  33. "29+8=37"

    Returns: { 10 }

  34. "FI+64B7=6575"

    Returns: { 20 }

  35. "AJBD+3BF=B338"

    Returns: { 20 }

  36. "7H+JE6=71"

    Returns: { }

  37. "J+B21=BF"

    Returns: { }

  38. "27829+B=27831"

    Returns: { 19 }

  39. "1GGH+H36=2F14"

    Returns: { 19 }

  40. "IE30+I9H8=1I518"

    Returns: { 19 }

  41. "JH+I40=J3H"

    Returns: { 20 }

  42. "H1FI+73FHA=81HE9"

    Returns: { 19 }

  43. "ACC4+329C7=3D46B"

    Returns: { 18 }

  44. "JHEGI+JF1=JIEBJ"

    Returns: { 20 }

  45. "E+B21C=B227"

    Returns: { 19 }

  46. "G04+CCHJ=D8I3"

    Returns: { 20 }

  47. "34G74+G=1027"

    Returns: { }

  48. "9F+2BDA=2B2D"

    Returns: { }

  49. "C+603=60F"

    Returns: { 16, 17, 18, 19, 20 }

  50. "E+H7AD=H7B7"

    Returns: { 20 }

  51. "F248G+8AC=F2D2B"

    Returns: { 17 }

  52. "C3+4F6D=4G1G"

    Returns: { 17 }

  53. "G24+F=G32"

    Returns: { 17 }

  54. "DFF+E6=ED4"

    Returns: { 17 }

  55. "2JB2+AF58H=17"

    Returns: { }

  56. "9+23=32"

    Returns: { 10 }

  57. "B0+JAGF=JB7F"

    Returns: { 20 }

  58. "873+1GICD=1H80G"

    Returns: { 19 }

  59. "BFA2E+33C=BFD66"

    Returns: { 20 }

  60. "D+AE=BC"

    Returns: { 15 }

  61. "69+7F7=84G"

    Returns: { 17 }

  62. "1234+8765=9999"

    Returns: { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }

  63. "0+0=0"

    Returns: { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }

  64. "1+A=0"

    Returns: { }

  65. "1A+1=2"

    Returns: { }

  66. "1+1=2"

    Returns: { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }

  67. "A+0=A"

    Returns: { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }

  68. "9+3=2"

    Returns: { }

  69. "FFFF+1=FFFG"

    Returns: { 17, 18, 19, 20 }

  70. "A+2=11"

    Returns: { 11 }


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: