fork download
  1. <?php
  2.  
  3. function getAngle($hours, $minutes) {
  4. $degreesMinutes = getDegreesForMinutes($minutes);
  5. $degreesHours = getDegreesForHours($hours);
  6. $hourArrowDegrees = getHourArrowDegrees($minutes);
  7. return abs($degreesMinutes - ($degreesHours + $hourArrowDegrees));
  8. }
  9.  
  10. function getDegreesForMinutes($minutes) {
  11. $degreesInMinute = 360 / 60;
  12. return $degreesInMinute * $minutes;
  13. }
  14.  
  15. function getDegreesForHours($hours) {
  16. $normalizedHours = $hours % 12;
  17. $degreesInFiveMinutes = 30;
  18. return $degreesInFiveMinutes * $normalizedHours;
  19. }
  20.  
  21. function getHourArrowDegrees($minutes) {
  22. return $minutes / 2;
  23. }
  24.  
  25. $testcases = [
  26. // час, минута, ожидаемый угол
  27. [12, 0, 0],
  28. [15, 20, 20],
  29. [3, 20, 20],
  30. [12, 30, 165],
  31. [10, 50, 25],
  32. ];
  33.  
  34. foreach ($testcases as list($hours, $minutes, $expectedAngle)) {
  35. $givenAngle = getAngle($hours, $minutes);
  36. echo "Время: {$hours}:{$minutes} ожидаемый угол: {$expectedAngle} дано: {$givenAngle}\n";
  37. }
  38.  
Success #stdin #stdout 0.02s 52488KB
stdin
Standard input is empty
stdout
Время: 12:0 ожидаемый угол: 0 дано: 0
Время: 15:20 ожидаемый угол: 20 дано: 20
Время: 3:20 ожидаемый угол: 20 дано: 20
Время: 12:30 ожидаемый угол: 165 дано: 165
Время: 10:50 ожидаемый угол: 25 дано: 25