jquery.balanced-gallery.js
// Used as part of the ordered partition function:
Used as part of the ordered partition function.
Used as part of the ordered partition function .
function createSolutionTable(weights, sections) {
        var elementCount = weights.length;
        var table = [];
        for (var i = 0; i < elementCount; i++) {
            var res = [];
            for (var j = 0; j < sections; j++) {
                res.push(0);
            }
            table.push(res);
        }
        var solution = [];
        for (var k = 0; k < elementCount-1; k++) {
            var res2 = [];
            for (var l = 0; l < sections-1; l++) {
                res2.push(0);
            }
            solution.push(res2);
        }
        for(var m = 0; m < elementCount; m++) {
            table[m][0] = weights[m].weight + (m !== 0 ? table[m-1][0] : 0);
        }
        for(var n = 0; n < sections; n++) {
            table[0][n] = weights[0].weight;
        }
        var subArraySort = function(a, b){ return a[0]-b[0]; };
        for(var p = 1; p < elementCount; p++) {
            for(var q = 1; q < sections; q++) {
                var results = [];
                for (var r = 0; r < p; r++) {
                    results.push([ Math.max( table[r][q - 1], table[p][0]-table[r][0] ), r ]);
                }
                var arr = results.sort(subArraySort)[0];
                table[p][q] = arr[0];
                solution[p-1][q-1] = arr[1];
            }
        }
        return solution;
    }
function createSolutionTable ( weights , sections ) { var elementCount = weights . length ; var table = [ ] ; for ( var i = 0 ; i < elementCount ; i ++ ) { var res = [ ] ; for ( var j = 0 ; j < sections ; j ++ ) { res . push ( 0 ) ; } table . push ( res ) ; } var solution = [ ] ; for ( var k = 0 ; k < elementCount - 1 ; k ++ ) { var res2 = [ ] ; for ( var l = 0 ; l < sections - 1 ; l ++ ) { res2 . push ( 0 ) ; } solution . push ( res2 ) ; } for ( var m = 0 ; m < elementCount ; m ++ ) { table [ m ] [ 0 ] = weights [ m ] . weight + ( m !== 0 ? table [ m - 1 ] [ 0 ] : 0 ) ; } for ( var n = 0 ; n < sections ; n ++ ) { table [ 0 ] [ n ] = weights [ 0 ] . weight ; } var subArraySort = function ( a , b ) { return a [ 0 ] - b [ 0 ] ; } ; for ( var p = 1 ; p < elementCount ; p ++ ) { for ( var q = 1 ; q < sections ; q ++ ) { var results = [ ] ; for ( var r = 0 ; r < p ; r ++ ) { results . push ( [ Math . max ( table [ r ] [ q - 1 ] , table [ p ] [ 0 ] - table [ r ] [ 0 ] ) , r ] ) ; } var arr = results . sort ( subArraySort ) [ 0 ] ; table [ p ] [ q ] = arr [ 0 ] ; solution [ p - 1 ] [ q - 1 ] = arr [ 1 ] ; } } return solution ; }
Used as part of the ordered partition function:
Used as part of the ordered partition function :