Statistics

Problem Statement for "TheArithmeticProgression"

Problem Statement

A triple (x, y, z) is called an arithmetic progression if the equality y - x = z - y holds.

You are given three ints a, b and c. Your goal is to change the triple (a, b, c) into an arithmetic progression. You are only allowed to change one of the three numbers. The change must proceed as follows: First, you choose a non-negative real (not necessarily integer) number r. Then, you either add r to one of the three given numbers, or you subtract r from one of them. Return the minimum value of r which allows you to create an arithmetic progression.

Definition

Class:
TheArithmeticProgression
Method:
minimumChange
Parameters:
int, int, int
Returns:
double
Method signature:
double minimumChange(int a, int b, int c)
(be sure your method is public)

Constraints

  • a will be between 0 and 1000, inclusive.
  • b will be between 0 and 1000, inclusive.
  • c will be between 0 and 1000, inclusive.

Examples

  1. 0

    1

    2

    Returns: 0.0

    The triple (0, 1, 2) is an arithmetic progression. Thus, you can choose r = 0.0 and add or subtract it from any of the given numbers without changing the triple.

  2. 0

    2

    1

    Returns: 1.5

    Note that while (0, 1, 2) is an arithmetic progression, you cannot rearrange the numbers within the triple. You can choose r = 1.5 and subtract it from b, obtaining the triple (0, 0.5, 1).

  3. 3

    2

    1

    Returns: 0.0

  4. 4

    4

    8

    Returns: 2.0

  5. 1000

    0

    0

    Returns: 500.0

  6. 1000

    1000

    1000

    Returns: 0.0

  7. 0

    0

    0

    Returns: 0.0

  8. 0

    1000

    0

    Returns: 1000.0

  9. 1000

    0

    1000

    Returns: 1000.0

  10. 1000

    0

    0

    Returns: 500.0

  11. 6

    7

    8

    Returns: 0.0

  12. 125

    882

    114

    Returns: 762.5

  13. 662

    663

    5

    Returns: 329.5

  14. 999

    122

    679

    Returns: 717.0

  15. 722

    1000

    900

    Returns: 189.0

  16. 722

    900

    1000

    Returns: 39.0

  17. 60

    90

    121

    Returns: 0.5

  18. 500

    301

    901

    Returns: 399.5

  19. 814

    502

    699

    Returns: 254.5

  20. 10

    1

    2

    Returns: 5.0

  21. 1

    3

    1

    Returns: 2.0

  22. 1

    2

    5

    Returns: 1.0

  23. 1

    5

    10

    Returns: 0.5

  24. 0

    1

    0

    Returns: 1.0

  25. 3

    5

    6

    Returns: 0.5

  26. 1

    2

    1

    Returns: 1.0

  27. 2

    4

    7

    Returns: 0.5

  28. 3

    1

    0

    Returns: 0.5

  29. 3

    5

    3

    Returns: 2.0

  30. 1

    2

    100

    Returns: 48.5

  31. 50

    100

    250

    Returns: 50.0

  32. 1

    4

    10

    Returns: 1.5

  33. 2

    2

    3

    Returns: 0.5

  34. 0

    0

    2

    Returns: 1.0

  35. 8

    1

    6

    Returns: 6.0

  36. 17

    10

    14

    Returns: 5.5

  37. 100

    1

    2

    Returns: 50.0

  38. 0

    0

    1000

    Returns: 500.0

  39. 4

    2

    1

    Returns: 0.5

  40. 1

    0

    1

    Returns: 1.0

  41. 1

    2

    2

    Returns: 0.5

  42. 10

    1

    10

    Returns: 9.0

  43. 1

    1

    3

    Returns: 1.0

  44. 2

    5

    2

    Returns: 3.0

  45. 5

    6

    8

    Returns: 0.5

  46. 1

    5

    6

    Returns: 1.5

  47. 1

    2

    4

    Returns: 0.5

  48. 1

    5

    8

    Returns: 0.5

  49. 0

    2

    0

    Returns: 2.0

  50. 500

    1

    2

    Returns: 250.0

  51. 9

    10

    4

    Returns: 3.5

  52. 2

    1

    3

    Returns: 1.5

  53. 4

    10

    30

    Returns: 7.0

  54. 0

    5

    100

    Returns: 45.0

  55. 1

    0

    2

    Returns: 1.5

  56. 5

    4

    2

    Returns: 0.5

  57. 3

    2

    2

    Returns: 0.5

  58. 2

    5

    5

    Returns: 1.5

  59. 2

    0

    1

    Returns: 1.5

  60. 0

    10

    100

    Returns: 40.0

  61. 1

    2

    8

    Returns: 2.5


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: