Question: I've been trying to make a div stretch down to my footer, with limited success. I've tried using jQuery to do this but it has some issues:

```
<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){

$(window).resize(function(){
var height = $(this).height() - $("#banner-wrapper").height() - $("#footer-wrapper").height()
$('#content').height(height);

})

$(window).resize(); //on page load

});//]]>  

</script>

```

This stretches the div down to the footer, but the problem is, it bases the height of of the **window size.** If your content extends past the fold, the #content div doesn't stretch to fit the content.

[http://matthewdail.com/staging/](http://www.matthewdail.com/staging/)  

Here you can see the jQuery doing it's job and stretching the #content div perfectly, but it doesn't extend to fit the content.

I've also tried some of the more common css tricks like:

```
html,body{
height:100%;
}

#content{
width:100%;
margin:0 auto -120px;
float:none;
min-height:100%;
height:auto !important;
height:100%;
}

```

I've searched everywhere but can't find a solution to this. Anyone have any ideas?

Answer: 
This solution is far from efficient:

```
    private static void Main()
    {
        List<List<int>> list = new List<List<int>>
            {
                new List<int>() {1, 3, 6}, //Booking 1
                new List<int>() {1, 2, 6}, //Booking 2
                new List<int>() {1}, //Booking 3
                new List<int>() {2, 3}
            };
        List<int[]> solutions = new List<int[]>();
        int[] solution = new int[list.Count];
        Solve(list, solutions, solution);
    }

    private static void Solve(List<List<int>> list, List<int[]> solutions, int[] solution)
    {
        if (solution.All(i => i != 0) && !solutions.Any(s => s.SequenceEqual(solution)))
            solutions.Add(solution);
        for (int i = 0; i < list.Count; i++)
        {
            if (solution[i] != 0)
                continue; // a caller up the hierarchy set this index to be a number
            for (int j = 0; j < list[i].Count; j++)
            {
                if (solution.Contains(list[i][j]))
                    continue;
                var solutionCopy = solution.ToArray();
                solutionCopy[i] = list[i][j];
                Solve(list, solutions, solutionCopy);
            }
        }
    }

```

It sounds like this can be solved more efficiently with Dynamic programming, but it's been a while since I took the relevant course.
A simple way to look at this problem would be to choose from all combinations of the list of values, where every value in the combination is unique.

First figure out what all the combinations of values are.

```
public static IEnumerable<IList<T>> Combinations<T>(IEnumerable<IList<T>> collections)
{
    if (collections.Count() == 1)
    {
        foreach (var item in collections.Single())
            yield return new List<T> { item };
    }
    else if (collections.Count() > 1)
    {
        foreach (var item in collections.First())
        foreach (var tail in Combinations(collections.Skip(1)))
            yield return new[] { item }.Concat(tail).ToList();
    }
}

```

Then you need a way to determine if all the values are unique. A simple way to figure that out would be to check if the count of distinct values equals the count of all values.

```
public static bool AllUnique<T>(IEnumerable<T> collection)
{
    return collection.Distinct().Count() == collection.Count();
}

```

Once you have all that, put it all together.

```
var collections = new[]
{
    new List<int> { 1, 3, 6 },
    new List<int> { 1, 2, 6 },
    new List<int> { 1 },
    new List<int> { 2, 3 },
};
var results =
    from combination in Combinations(collections)
    where AllUnique(combination)
    select combination;
// results:
//  3,6,1,2
//  6,2,1,3

```