-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime_task.php
More file actions
35 lines (21 loc) · 1.18 KB
/
time_task.php
File metadata and controls
35 lines (21 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title> Millitary Task </title>
</head>
<body> <?php
define("X", 12); //interger X holding the limited time it will take to complete a task
$A = array(7, 6, 5, 3, 4, 2, 1); // interger Array A holding time value it will take to complete different task
$currentTime = 0; //Declaration and Initialization of currentTime variable
$numberOfThings = 0; //Declaration and Initialization of numberOfThings variable
sort($A); //Sorting A array in non-decreasing order
while ($currentTime <= X) { //Iteration block starts here
$currentTime += $A[$numberOfThings]; //Adding completion time of the selected to-do item to currentTime variable
$numberOfThings++; //Incrementing numberOfThings variable by one
} //Iteration block stops here
?>
<span>The maximum number of tasks to be completed by the military unit, in limited time of
<strong><?php echo X . " minutes"; ?></strong> is: </span><strong><?php echo $numberOfThings; ?> tasks</strong>
</body>
</html>