activity/translator/translator.php
protected function _getPowerSet(array $set = array(), $min_length = 1)
    {
        $elements = count($set);
        $size     = pow(2, $elements);
        $members  = array();

        for ($i = 0; $i < $size; $i++)
        {
            $b      = sprintf("%0" . $elements . "b", $i);
            $member = array();
            for ($j = 0; $j < $elements; $j++) {
                if ($b{$j} == '1') $member[] = $set[$j];
            }

            if (count($member) >= $min_length)
            {
                if (!isset($members[count($member)])) {
                    $members[count($member)] = array();
                }

                // Group members by number of elements they contain.
                $members[count($member)][] = $member;
            }
        }

        // Sort members by number of elements (key value).
        ksort($members, SORT_NUMERIC);

        $power = array();

        // We want members with greater amount of elements first.
        foreach (array_reverse($members) as $subsets) {
            $power = array_merge($power, $subsets);
        }

        return $power;
    }
protected function _getPowerSet(array $set = array(), $min_length = 1)
    {
        $elements = count($set);
        $size     = pow(2, $elements);
        $members  = array();

        for ($i = 0; $i < $size; $i++)
        {
            $b      = sprintf("%0" . $elements . "b", $i);
            $member = array();
            for ($j = 0; $j < $elements; $j++) {
                if ($b{$j} == '1') $member[] = $set[$j];
            }

            if (count($member) >= $min_length)
            {
                if (!isset($members[count($member)])) {
                    $members[count($member)] = array();
                }

                // Group members by number of elements they contain.
                $members[count($member)][] = $member;
            }
        }

        // Sort members by number of elements (key value).
        ksort($members, SORT_NUMERIC);

        $power = array();

        // We want members with greater amount of elements first.
        foreach (array_reverse($members) as $subsets) {
            $power = array_merge($power, $subsets);
        }

        return $power;
    }
protected function _getPowerSet ( array $ set = array ( ) , $ min_length = 1 ) { $ elements = count ( $ set ) ; $ size = pow ( 2 , $ elements ) ; $ members = array ( ) ; for ( $ i = 0 ; $ i < $ size ; $ i ++ ) { $ b = sprintf ( "%0" . $ elements . "b" , $ i ) ; $ member = array ( ) ; for ( $ j = 0 ; $ j < $ elements ; $ j ++ ) { if ( $ b { $ j } == '1' ) $ member [ ] = $ set [ $ j ] ; } if ( count ( $ member ) >= $ min_length ) { if ( ! isset ( $ members [ count ( $ member ) ] ) ) { $ members [ count ( $ member ) ] = array ( ) ; } // Group members by number of elements they contain. $ members [ count ( $ member ) ] [ ] = $ member ; } } // Sort members by number of elements (key value). ksort ( $ members , SORT_NUMERIC ) ; $ power = array ( ) ; // We want members with greater amount of elements first. foreach ( array_reverse ( $ members ) as $ subsets ) { $ power = array_merge ( $ power , $ subsets ) ; } return $ power ; }
Returns the power set of a set represented by the elements contained in an array.

For convenience, the elements are ordered from size (subsets with more elements first).

@param     array $set        The set to get the power set from.
@param     int   $min_length The minimum amount of elements that a subset from the power set may contain.
@return array The power set represented by an array of arrays containing elements from the provided set.
Returns the power set of a set represented by the elements contained in an array .