DEV Community

Discussion on: Daily Challenge #280 - Driving School

Collapse
 
peter279k profile image
peter279k

Here is my simple solution with PHP and using while loop to resolve this challenge :).

function cost($mins) {
  if ($mins <= 60) {
    return 30;
  }

  $result = 30;
  $mins -= 60;
  $halfHour = 0;

  while ($mins - 30 > 0) {
    $halfHour += 1;
    $mins -= 30;
  }

  if (30 - $mins >= 0 && $mins >= 6) {
    $halfHour += 1;
  }

  return $result + $halfHour * 10;
}