Do you know how to vectorize 14 nested loops ? (18 but the last of each block of for
is predetermined by the others in the same block. I use for
because it's easier to read)
max2=0
for(M_P in 0:9)
{
for(M_D in 0:(9-M_P))
{
for(M_A in 0:(9-M_P-M_D))
{
for(M_CC in 0:(9-M_P-M_D-M_A))
{
for(M_CD in (9-M_P-M_D-M_A-M_CC))
{
for(G_D in 0:9)
{
for(G_A in 0:(9-G_D))
{
for(G_CC in 0:(9-G_D-G_A))
{
for(G_CD in (9-G_D-G_A-G_CC))
{
for(S_D in 0:9)
{
for(S_A in 0:(9-S_D))
{
for(S_CC in 0:(9-S_D-S_A))
{
for(S_CD in (9-S_D-S_A-S_CC))
{
for(Q_P in 0:3)
{
for(Q_D in 0:(3-Q_P))
{
for(Q_A in 0:(3-Q_P-Q_D))
{
for(Q_CC in 0:(3-Q_P-Q_D-Q_A))
{
for(Q_CD in (3-Q_P-Q_D-Q_A-Q_CC))
{
max1=1.1*M_P+2.1*M_D+3.1*M_A+4.1*M_CC+4*M_CD+2*G_D+5*G_A+1.5*G_CC+3*G_CD+5*S_D+4*S_A+3*S_CC+6*S_CD+2*Q_P+3*Q_D+2.2*Q_A+3*Q_CC+4*Q_CD
if(max1>max2)
{
max2=max1
}}}}}}}}}}}}}}}}}}}
print(max2)
I need to do this little optimization work but i have no idea how to vetorize it since I'm new in both R and programmation ! Basically I have 3 set of 9 slots and 1 set of 3 slots. In slots I can put some kind of badges that have certain value and those nested loops search for the best combination of badges possible. Of course in the present example you just put badges with higher values but in the real case the max1
calculation is bit more complicated and non trivial (I can give you the whole code if you need it).