CountNonDivisible   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 0
cbo 0
dl 0
loc 30
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B solution() 0 27 6
1
<?php
2
3
namespace Lesson09;
4
5
class CountNonDivisible
6
{
7
    public function solution($A)
8
    {
9
        $N = count($A);
10
        $countValues = array_count_values($A);
11
        $occurrences = array_fill(0, $N * 2 + 1, 0);
12
        $answer = array_fill(0, $N * 2 + 1, 0);
13
        $result = array_fill(0, $N, 0);
14
        foreach ($countValues as $key => $value) {
15
            $occurrences[$key] = $value;
16
        }
17
18
        for ($i = 1; $i <= $N * 2; $i++) {
0 ignored issues
show
Comprehensibility Bug introduced by
Loop incrementor ($i) jumbling with inner loop
Loading history...
19
            $num = $occurrences[$i];
20
            if ($num == 0) {
21
                continue;
22
            }
23
            for ($j = $i; $j <= $N * 2; $j += $i) {
24
                $answer[$j] -= $num;
25
            }
26
        }
27
28
        for ($i = 0; $i < $N; $i++) {
29
            $result[$i] = $N + $answer[$A[$i]];
30
        }
31
32
        return $result;
33
    }
34
}
35