-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0905.php
More file actions
46 lines (40 loc) · 1.01 KB
/
0905.php
File metadata and controls
46 lines (40 loc) · 1.01 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
35
36
37
38
39
40
41
42
43
44
45
46
<?php
declare (strict_types = 1);
// echo 'Proceed now';
function prepareOddAry($start, $end)
{
$oddAry = [];
do {
if ($start === 1) {
array_push($oddAry, $start);
} else {
($start % 2 === 0) ? '' : array_push($oddAry, $start);
}
$start++;
} while ($start <= $end);
return $oddAry;
}
function rowSumOddNumbers(int $n): int
{
$oddAry = prepareOddAry(1, 2000);
$startValue = $n * ($n - 1);
$searchOddFromAry = ($startValue % 2 == 0) ? $startValue + 1 : $startValue;
// echo $searchOddFromAry;
$resultKey = array_search($searchOddFromAry, $oddAry);
// echo $resultKey;
$newSubAry = [];
$a = $resultKey;
$i = 0;
do {
array_push($newSubAry, $oddAry[$a]);
$a++;
$i++;
// echo $i;
} while ($i < $n);
// print_r($newSubAry);
return array_sum($newSubAry);
}
// echo rowSumOddNumbers(13);
// echo '</br>';
// print_r(prepareOddAry(1, 200));
echo pow(101, 3);