Statistics

Problem Statement for "Errors"

Problem Statement

When data are the result of measurements, their accuracy must be considered. Suppose that v1 and v2 are two values, and that m1 and m2 are measurements of those values, with possible error e. That means that v1 is known to be somewhere in the interval m1-e to m1+e inclusive, and similarly v2 is known to be in the interval m2-e to m2+e inclusive.

When we perform an arithmetic operation, the actual result v1 op v2 cannot be determined exactly, but we can determine the interval in which it is known to lie. Create a class Errors that contains the method range that takes two int measurements, m1 and m2, the possible error e, and an arithmetic operation op ('+', '-', '*', or '/') as inputs. The method returns the range, the highest possible result of v1 op v2 minus the lowest possible result, as a String.

m1 and m2 will be given in whole units, and e will be an int giving the error in thousandths of a unit. All operations are "real" operations not restricted or truncated to integers. The return value should be the range rounded to 3 decimal places (round .0005 up). It must contain no leading 0s, and must contain a decimal point followed by exactly three digits. If the range is not finite, or if the undefined result 0/0 is possible, return "INFINITY"

Definition

Class:
Errors
Method:
range
Parameters:
int, int, int, char
Returns:
String
Method signature:
String range(int m1, int m2, int e, char op)
(be sure your method is public)

Notes

  • '/' denotes real division, not division truncated to the nearest integer
  • the error in a value may be greater than its size (see example 1)

Constraints

  • m1 will be between -10,000 and 10,000 inclusive
  • m2 will be between -10,000 and 10,000 inclusive
  • e will be between 1 and 10,000 inclusive
  • op will be '+','-','*', or '/'
  • all values within .00001 of the range will round to the same 3-place result

Examples

  1. -1

    2

    500

    '-'

    Returns: "2.000"

    The smallest result would be (-1 - .500) - (2 + .500) = -4 The biggest result would be (-1 + .500) - (2 - .500) = -2 The range is therefore -2 - -4 = 2.

  2. 2

    -1

    1250

    '*'

    Returns: "8.125"

    The smallest result would be (3.250 * -2.250) = -7.3125 The largest result would be (3.250 * .250) = .8125 The range is .8125 - -7.3125 = 8.125

  3. 2

    1

    1200

    '/'

    Returns: "INFINITY"

    The interval in which the divisor is known to lie includes 0.

  4. 9999

    1

    999

    '/'

    Returns: "9994997.499"

    9999, 1, 999, '/': return "9994997.499

  5. 7237

    3590

    2

    '+'

    Returns: ".008"

  6. 0

    0

    10000

    '+'

    Returns: "40.000"

  7. -5

    5

    9999

    '-'

    Returns: "39.996"

  8. 2

    7

    7001

    '*'

    Returns: "196.042"

  9. -2

    7

    6997

    '*'

    Returns: "195.874"

  10. -17

    -8

    6543

    '*'

    Returns: "327.150"

  11. 0

    0

    92

    '*'

    Returns: ".017"

  12. 0

    1

    1

    '/'

    Returns: ".002"

  13. 0

    0

    1

    '/'

    Returns: "INFINITY"

  14. 0

    1

    1

    '/'

    Returns: ".002"

  15. 5

    0

    1

    '/'

    Returns: "INFINITY"

  16. 2

    1

    1000

    '/'

    Returns: "INFINITY"

  17. 2

    -5

    5000

    '/'

    Returns: "INFINITY"

  18. 10000

    10

    9999

    '/'

    Returns: "10009499.475"

  19. 1

    60

    10000

    '/'

    Returns: ".400"

  20. 5

    5

    2499

    '/'

    Returns: "2.665"

  21. 7237

    3590

    2

    '+'

    Returns: ".008"

  22. 100

    20

    50

    '/'

    Returns: ".030"

  23. -500

    -500

    1000

    '*'

    Returns: "2000.000"

  24. -100

    100

    10

    '*'

    Returns: "4.000"

  25. 10000

    200

    1

    '/'

    Returns: ".001"

  26. 20

    10

    3

    '/'

    Returns: ".002"

  27. 1

    0

    100

    '/'

    Returns: "INFINITY"

  28. 10000

    205

    1

    '/'

    Returns: ".000"

  29. 0

    10

    1000

    '/'

    Returns: ".222"

  30. 0

    10

    1

    '/'

    Returns: ".000"

  31. 1

    -1

    100

    '/'

    Returns: ".404"

  32. 2

    1

    500

    '/'

    Returns: "4.000"

  33. 10000

    10000

    10000

    '+'

    Returns: "40.000"

  34. 1

    5

    2000

    '/'

    Returns: "1.333"

  35. 10000

    10000

    10000

    '*'

    Returns: "400000.000"

  36. 3

    5

    3000

    '/'

    Returns: "3.000"

  37. 1

    5

    12

    '-'

    Returns: ".048"

  38. 4

    0

    40

    '/'

    Returns: "INFINITY"

  39. 0

    2

    500

    '/'

    Returns: ".667"

  40. 0

    0

    10000

    '+'

    Returns: "40.000"

  41. 10000

    10000

    10000

    '/'

    Returns: ".004"

  42. 1

    1

    1000

    '-'

    Returns: "4.000"

  43. 5

    5

    1

    '+'

    Returns: ".004"


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: