Conditions | 4 |
Paths | 3 |
Total Lines | 12 |
Code Lines | 7 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
34 | public static function isHappy2(int $n): bool |
||
35 | { |
||
36 | if ($n <= 0) { |
||
37 | return false; |
||
38 | } |
||
39 | $visited = []; |
||
40 | while ($n !== 1 && ! in_array($n, $visited, true)) { |
||
41 | array_push($visited, $n); |
||
42 | $n = array_sum(array_map(fn ($x) => $x ** 2, str_split((string) $n))); |
||
|
|||
43 | } |
||
44 | |||
45 | return !in_array($n, $visited, true); |
||
46 | } |
||
48 |