$value) { $bits[$position][] = $value; } } $gammaRate = ''; $epsilonRate = ''; foreach ($bits as $bit) { $zeros = array_filter($bit, static fn ($value): bool => $value === '0'); $ones = array_filter($bit, static fn ($value): bool => $value === '1'); $gammaRate .= ($ones > $zeros) ? '1' : '0'; $epsilonRate .= ($ones < $zeros) ? '1' : '0'; } return (int) (bindec($gammaRate) * bindec($epsilonRate)); } }