-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBetween Two Sets.php
More file actions
43 lines (32 loc) · 946 Bytes
/
Between Two Sets.php
File metadata and controls
43 lines (32 loc) · 946 Bytes
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
<?php
/*
PROBLEM:
There will be two arrays of integers. Determine all integers that satisfy the following two conditions:
The elements of the first array are all factors of the integer being considered
The integer being considered is a factor of all elements of the second array
These numbers are referred to as being between the two arrays. Determine how many such numbers exist.
*/
// Solution
function getTotalX($a, $b) {
$result = 0;
for ($i = $a[count($a) -1]; $i <= $b[0]; $i++) {
$countA = 0;
$countB = 0;
foreach($a as $element) {
if ($i % $element == 0)
$countA++;
}
foreach($b as $element) {
if ($element % $i == 0)
$countB++;
}
if ($countA == count($a) && $countB == count($b)) {
$result++;
}
}
return $result;
}
$a = [2, 6];
$b = [24,36];
echo getTotalX($a, $b);
?>