Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript

times: [11, 3, 8, 16, 9, 13, 5, 8, 16]
for (var i = n - 1; i >= 2; --i)
    {
        if (c == -1)
        {
            c = i;
        }
        else if (d == -1)
        {
            d = i;
        }
        if (c != -1 && d != -1)
        {if (times[c] + times[d] + (times[a] * 2) >
                    (times[b] * 2) + times[a] + times[c])
				{
					
					result += (times[b] * 2) + times[a] +
                      times[c];
				}
				else
				{
					
					result += times[c] + times[d] + 
                      (times[a] * 2);
				}
				c = -1;
				d = -1;
			}
    }
    if (c != -1)
    {result += times[a] + times[b] + times[c];}
    else
    {result += times[b];}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript
ADD COMMENT
Topic
Name
6+2 =