13 private static function factors(
float $value): array
15 $startVal = floor(sqrt($value));
18 for (
$i = $startVal;
$i > 1; --
$i) {
19 if (($value %
$i) == 0) {
20 $factorArray = array_merge($factorArray, self::factors($value /
$i));
21 $factorArray = array_merge($factorArray, self::factors(
$i));
22 if (
$i <= sqrt($value)) {
27 if (!empty($factorArray)) {
33 return [(int) $value];
58 $anyNonNulls += (int) ($value1 !==
null);
61 $arrayArgs[] = (int) $value;
62 $anyZeros += (int) !((
bool) $value);
69 return $e->getMessage();
73 $allPoweredFactors = [];
75 foreach ($arrayArgs as $value) {
77 $myCountedFactors = array_count_values($myFactors);
78 $myPoweredFactors = [];
79 foreach ($myCountedFactors as $myCountedFactor => $myCountedPower) {
80 $myPoweredFactors[$myCountedFactor] = $myCountedFactor ** $myCountedPower;
84 foreach ($allPoweredFactors as $allPoweredFactor) {
85 $returnValue *= (int) $allPoweredFactor;
93 foreach ($myPoweredFactors as $myPoweredValue => $myPoweredFactor) {
94 if (isset($allPoweredFactors[$myPoweredValue])) {
95 if ($allPoweredFactors[$myPoweredValue] < $myPoweredFactor) {
96 $allPoweredFactors[$myPoweredValue] = $myPoweredFactor;
99 $allPoweredFactors[$myPoweredValue] = $myPoweredFactor;
An exception for terminatinating execution or to throw for unit testing.
static flattenArray($array)
Convert a multi-dimensional array to a simple 1-dimensional array.
static validateNotNegative($number, ?string $except=null)
Confirm number >= 0.
static validateNumericNullSubstitution($number, $substitute)
Validate numeric, but allow substitute for null.
static evaluate(... $args)
LCM.
static factors(float $value)
static processPoweredFactors(array &$allPoweredFactors, array &$myPoweredFactors)
static testNonNulls(int $anyNonNulls)