Statistics

Problem Statement for "TurnFinder"

Problem Statement

You are given the String representation of three points, p1, p2, and p3. You are programming the turning algorithm for an automated navigation / path-finding system. Imagine a vehicle has just moved along the straight-line path from p1 to p2 and now seeks to move along the straight-line path from p2 to p3. Assume the vehicle uses a synchro-drive movement system (it can turn in place, kind of like the wheels of an office chair).

Let "theta" be the angle of the turn rounded to the nearest integer degree (turn angles exactly between two integers will not be allowed, see constraints).

  • If theta < 10, no turn is required, return "CONTINUE".
  • If 170 <=; theta, return "U-TURN".
  • If 10 <= theta < 60, return "TURN SLIGHT <dir>:theta"
  • If 60 <= theta < 120, return "TURN <dir>:theta"
  • If 120 <= theta < 170, return "TURN SHARP <dir>:theta"

The above diagram shows the basic algorithm for determining the turn angle. Notice that turn can be executed by turning right with angle A or left with angle (360 - A). For this problem, always choose the smaller turn. The diagram only shows the case where t1 - t2 is the smaller turn. This convenience is not always the case.

The points will be of the form: <x>:<y> and x and y are perpendicular, equal-length units (unlike latitude and longitude, which are not equal-length units on most parts of Earth). In other words, x and y are standard Cartesian coordinates.
For example, "5:3" or "11:-7"
Note that moving from 0:0 to 0:3 to 3:3 requires a 90 degree RIGHT turn.

The return value must be of the form: <TURN <direction>:<angle> or "CONTINUE" or "U-TURN"
For example, "TURN RIGHT:90" or "TURN SLIGHT LEFT:170"

Definition

Class:
TurnFinder
Method:
turnAngle
Parameters:
String, String, String
Returns:
String
Method signature:
String turnAngle(String p1, String p2, String p3)
(be sure your method is public)

Notes

  • The shorter turn out of left and right will always be the one with the angle less than 180.
  • The first and third point may be equal (p1 == p3).

Constraints

  • No leading zeros will be allowed for the coordinates.
  • No two consecutive points may be equal (p1 != p2, p2 != p3).
  • The points will be of the form: : where x and y are integers between -100 and 100 inclusive with no leading zeros.
  • Some inputs will not be allowed because it can cause hardware-dependent rounding errors. Inputs where the turn is within 0.01 degrees of rounding ambiguity will not be allowed.

Examples

  1. "0:0"

    "0:3"

    "3:3"

    Returns: "TURN RIGHT:90"

  2. "47:32"

    "20:80"

    "-5:0"

    Returns: "TURN SHARP LEFT:133"

  3. "0:0"

    "20:20"

    "50:50"

    Returns: "CONTINUE"

  4. "0:0"

    "50:50"

    "0:0"

    Returns: "U-TURN"

  5. "50:50"

    "30:30"

    "20:-5"

    Returns: "TURN SLIGHT LEFT:29"

  6. "0:0"

    "0:10"

    "-19:9"

    Returns: "TURN LEFT:93"

  7. "0:0"

    "0:10"

    "1:6"

    Returns: "TURN SHARP RIGHT:166"

  8. "85:-71"

    "-56:57"

    "-10:-65"

    Returns: "TURN SHARP LEFT:153"

  9. "0:0"

    "-10:0"

    "-10:-1"

    Returns: "TURN LEFT:90"

  10. "0:0"

    "0:-1"

    "-10:-1"

    Returns: "TURN RIGHT:90"

  11. "-100:0"

    "100:0"

    "-100:1"

    Returns: "U-TURN"

  12. "0:0"

    "1:7"

    "2:-8"

    Returns: "TURN SHARP RIGHT:168"

  13. "0:0"

    "-3:-3"

    "5:5"

    Returns: "U-TURN"

  14. "0:0"

    "-100:-100"

    "-100:100"

    Returns: "TURN SHARP RIGHT:135"

  15. "0:0"

    "30:40"

    "60:80"

    Returns: "CONTINUE"

  16. "3:0"

    "0:4"

    "0:0"

    Returns: "TURN SHARP LEFT:143"

  17. "40:-30"

    "-20:2"

    "-18:10"

    Returns: "TURN RIGHT:76"

  18. "-50:0"

    "-50:50"

    "-41:100"

    Returns: "TURN SLIGHT RIGHT:10"

  19. "0:0"

    "0:1"

    "-10:11"

    Returns: "TURN SLIGHT LEFT:45"

  20. "0:0"

    "0:1"

    "-40:24"

    Returns: "TURN LEFT:60"

  21. "5:5"

    "3:0"

    "-20:29"

    Returns: "TURN SHARP RIGHT:120"

  22. "0:0"

    "1:15"

    "5:22"

    Returns: "TURN SLIGHT RIGHT:26"

  23. "-5:20"

    "30:-2"

    "-10:-10"

    Returns: "TURN SHARP RIGHT:137"

  24. "0:1"

    "0:0"

    "1:0"

    Returns: "TURN LEFT:90"

  25. "0:0"

    "1:15"

    "5:22"

    Returns: "TURN SLIGHT RIGHT:26"

  26. "-5:20"

    "30:-2"

    "-10:-10"

    Returns: "TURN SHARP RIGHT:137"

  27. "0:1"

    "0:0"

    "1:0"

    Returns: "TURN LEFT:90"


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: