Untitled
unknown
plain_text
3 years ago
1.3 kB
4
Indexable
<?php function isEven($number) { if ($number % 2 == 0) { return true; } return false; } function biggerThanTwo($number) { if ($number > 2) { return isEven($number); } } function isPrime($number) { $found = true; for ($i = 2; $i <= sqrt($number); $i++) { if ($number % $i == 0) { $found = false; } } return $found; } function allPrimeLess($number) { $primes = []; foreach (range(2, $number) as $countable) if (isPrime($countable)) array_push($primes, $countable); return $primes; } function searchInArray(array $prams, string $search): bool { $found = false; foreach ($prams as $param) if (in_array($search, $param)) $found = true; return $found; } function goldenBakh($number) { if (!biggerThanTwo($number)) return false; $primes = allPrimeLess($number); $arrayPrimes = []; foreach ($primes as $prime) for ($j = 0; $j < count($primes); $j++) if ($prime + $primes[$j] == $number) if (!searchInArray($arrayPrimes, $prime)) array_push($arrayPrimes, [$prime, $primes[$j]]); return $arrayPrimes; } var_dump(goldenBakh(12));
Editor is loading...