you have 3 bucket and 3 color so total combination is 3!=6
nedd 3 array b[4],c[4],g[4] and another a[7]
a[1]=b[2]+b[3]+g[1]+g[2]+c[1]+c[3]; // BCG
a[2]=b[2]+b[3]+g[1]+g[3]+c[1]+c[2];// BGC
a[3]=b[1]+b[3]+g[1]+g[2]+c[2]+c[3];//CBG
a[4]=b[1]+b[2]+g[1]+g[3]+c[2]+c[3];//CGB
a[5]=b[1]+b[3]+g[2]+g[3]+c[1]+c[2];//GBC
a[6]=b[1]+b[2]+g[2]+g[3]+c[1]+c[3];//GCB
then you need check smallest value from a[] and check smallest value index print that index color combination
i.e. if index 4 for smallest value then output CGB.
no kidding. so it IS brute force.
ReplyDeleteI was thinking that there was some elegant way of determining what color each bin should be rather than compute every permutation.
Becomes redonculouse for large n. I guess thats why they use the exclamation mark for factorials.