Advertisement
Valleri

Boxes In Boxes - sprintf func

Jul 19th, 2014
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Solve() {
  2.     var w1 = parseInt(arguments[0]);
  3.     var h1 = parseInt(arguments[1]);
  4.     var d1 = parseInt(arguments[2]);
  5.  
  6.     var w2 = parseInt(arguments[3]);
  7.     var h2 = parseInt(arguments[4]);
  8.     var d2 = parseInt(arguments[5]);
  9.  
  10.     //check if the first fits in the second
  11.     checkBoxes(w1, h1, d1, w2, h2, d2);
  12.     checkBoxes(w1, h1, d1, w2, d2, h2);
  13.     checkBoxes(w1, h1, d1, h2, w2, d2);
  14.     checkBoxes(w1, h1, d1, h2, d2, w2);
  15.     checkBoxes(w1, h1, d1, d2, w2, h2);
  16.     checkBoxes(w1, h1, d1, d2, h2, w2);
  17.  
  18.     //check if the second fits in the first
  19.    
  20.     checkBoxes(w2, h2, d2, w1, h1, d1);
  21.     checkBoxes(w2, h2, d2, w1, d1, h1);
  22.     checkBoxes(w2, h2, d2, h1, w1, d1);
  23.     checkBoxes(w2, h2, d2, h1, d1, w1);
  24.     checkBoxes(w2, h2, d2, d1, w1, h1);
  25.     checkBoxes(w2, h2, d2, d1, h1, w1);
  26.  
  27.     function sprintf(format, etc) {
  28.         var arg = arguments;
  29.         var i = 1;
  30.         return format.replace(/%((%)|s|d)/g, function (m) { return m[2] || arg[i++] })
  31.     }
  32.  
  33.     function checkBoxes(w1, h1, d1, w2, h2, d2) {
  34.         if (w1 < w2 && h1 < h2 && d1 < d2) {
  35.            console.log(sprintf('(%d, %d, %d) < (%d, %d, %d)', w1, h1, d1, w2, h2, d2));
  36.         }
  37.     }
  38. }
  39.  
  40.  
  41. Solve(9, 6, 2, 5, 1, 7);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement