Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function Distance($x1, $y1, $x2, $y2)
- {
- return sqrt(pow($x1 - $x2, 2) + pow($y1 - $y2, 2));
- }
- list($x1, $y1, $x2, $y2, $x3, $y3) = explode(", ", trim(fgets(STDIN)));
- /*
- preg_match_all("/(-?\d*\.{0,1}\d+)/", trim(fgets(STDIN)), $input);
- list($x1, $y1, $x2, $y2, $x3, $y3) = $input[0];
- */
- $d3 = Distance($x1, $y1, $x2, $y2);
- $d1 = Distance($x2, $y2, $x3, $y3);
- $d2 = Distance($x1, $y1, $x3, $y3);
- $trip1 = $d1 + $d3;
- $trip2 = $d1 + $d2;
- $trip3 = $d2 + $d3;
- if ($trip3 < $trip2 && $trip3 < $trip1) {
- echo "2->1->3: " . $trip3;
- } elseif ($trip2 < $trip1) {
- echo "1->3->2: " . $trip2;
- } else {
- echo "1->2->3: " . $trip1;
- }
Add Comment
Please, Sign In to add comment