0
$\begingroup$

Asking this question on SO, I have been advised to post it here. I will be using Javascript to implement :

Please consider a row of size 12. On that row, I want to place some items that have 3 different width : 1, 2 and 3.

I would like to get all the possible combination of items on that row such that the sum of their width is equal to the row size.

For example, I could have :

[1,1,1,1,1,1,1,1,1,1,1,1] (12 items of size 1)

[2,2,2,2,2,2] (6 items of size 2)

[3,3,3,3] (4 items of size 3)

[3,3,3,1,1,1] (3 items of size 3 + 3 items of size 1)

[2,2,1,1,3,3] (2 items of size 2 + 2 items of size 1 + 2 items of size 3)

  • 0
    Presumably, order matters - that is, $[3,3,3,2,1]$ and $[3,2,1,3,3]$ are considered different.2012-06-20
  • 0
    What are you going to do with all the arrangements, once you have them? There will be a lot of them, you know. Just using four 2s and four 1s, there will be 70 arrangements. Just using two 3s, two 2s, and two 1s, there will be another 90. All told, I'm sure there are over 1,000.2012-06-21
  • 0
    @GerryMyerson Good guesstimate! There are 927.2012-06-21
  • 0
    @Gerr Myerson. I am trying to tile object of different width on rows on a screen. Similar to : http://images.google.com/search?q=tree&biw=1440&bih=828&sei=oQvjT5OAGIm40QHIuZCjAw&tbm=isch Except I set 3 ratio for the images !2012-06-21

1 Answers 1