SHARE
TWEET

4-cart L-bumper exhaustive searcher [Dwarf Fortress]

a guest Jul 21st, 2018 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2.     <meta charset="UTF-8"/>
  3. <head>
  4. </head>
  5. <body>
  6.     ▲<br/>
  7.     ║<br/>
  8.     ╚=▲
  9. <p onChange=estimate()>
  10.   <button class="js-btn" onclick="calculate();">Calculate</button> Only display values <textarea id="js-regexplimiter" cols="50" rows="1"></textarea> Force double weight difference(inelastic)<input type="checkbox" id="inelastic"></input><br/>
  11.   Friction 1<textarea class="js-regexpF1" cols="50" rows="1">10</textarea>Cart 1 min<textarea class="js-regexpm1" cols="50" rows="1">314</textarea>Cart 1 max<textarea class="js-regexpW1" cols="50" rows="1">314</textarea><br/>
  12.   Friction 2<textarea class="js-regexpF2" cols="50" rows="1">10</textarea>Cart 2 min<textarea class="js-regexpm2" cols="50" rows="1">4</textarea>Cart 2 max<textarea class="js-regexpW2" cols="50" rows="1">4</textarea><br/>
  13.   Friction 3<textarea class="js-regexpF3" cols="50" rows="1">10</textarea>Cart 3 min<textarea class="js-regexpm3" cols="50" rows="1">15</textarea>Cart 3 max<textarea class="js-regexpW3" cols="50" rows="1">15</textarea><br/>
  14.   Friction 4<textarea class="js-regexpF4" cols="50" rows="1">10</textarea>Cart 4 min<textarea class="js-regexpm4" cols="50" rows="1">134</textarea>Cart 4 max<textarea class="js-regexpW4" cols="50" rows="1">134</textarea><br/>
  15.   Friction 5<textarea class="js-regexpF5" cols="50" rows="1">10</textarea>
  16. </p>
  17. <p>
  18.   <textarea id="js-output" cols="50" rows="10"></textarea><br/>
  19.  
  20.   <button class="js-btn2" onclick="estimate();">estimate nr of calcs</button> <span id=timetaken>Seconds</span><textarea id="js-estimate" cols="50" rows="1"></textarea> <br/>
  21.  
  22.  
  23. </p>
  24.     <script>
  25. function gid(m){return document.getElementById(m);}
  26. function qs(n) {return document.querySelector(n);}
  27. var mfloor = Math.floor;
  28. var mmin = Math.min;
  29. var mceil = Math.ceil;
  30. function outputspeed(inputspeed,inputcartweight,outputcartweight,friction){
  31. return (mfloor(inputspeed*mmin(1,inputcartweight/outputcartweight))-friction);
  32. }
  33. function estimate() {
  34. var minweights = new Array();
  35. var maxweights = new Array();
  36.  
  37. for(var i=0; i<4; i++){
  38.     minweights[i] = parseInt(qs('.js-regexpm'+(i+1)).value.length > 0 ? qs('.js-regexpm'+(i+1)).value : 0);
  39. }
  40.  
  41. for(var i=0; i<4; i++){
  42.     maxweights[i] = parseInt(qs('.js-regexpW'+(i+1)).value.length > 0 ? qs('.js-regexpW'+(i+1)).value : 0);
  43. }
  44. var rv=1;
  45. for(var i=0;i<4;i++){
  46.     rv=rv*(maxweights[i]-minweights[i]+1);
  47. }
  48.  
  49.     gid("js-estimate").value=rv*5.452/60466176;
  50.    
  51. }
  52.  
  53. function calculate(){
  54. var rn = Date.now();
  55. var frictions = new Array();
  56. var minweights = new Array();
  57. var maxweights = new Array();
  58.  
  59. for(var i=0; i<5; i++){
  60.     frictions[i] = parseInt(qs('.js-regexpF'+(i+1)).value.length > 0 ? qs('.js-regexpF'+(i+1)).value : 0);
  61. }
  62.  
  63. for(var i=0; i<4; i++){
  64.     minweights[i] = parseInt(qs('.js-regexpm'+(i+1)).value.length > 0 ? qs('.js-regexpm'+(i+1)).value : 0);
  65. }
  66.  
  67. for(var i=0; i<4; i++){
  68.     maxweights[i] = parseInt(qs('.js-regexpW'+(i+1)).value.length > 0 ? qs('.js-regexpW'+(i+1)).value : 0);
  69. }
  70.  
  71.     var cyclelength=0;
  72.     var cycleforwards=0;
  73.     var cycleback=0;
  74.     var s=new Array();
  75.     var sn=0;
  76.     var limiter = gid('js-regexplimiter').value.length > 0 ? parseInt(gid('js-regexplimiter').value) : false;
  77.     var c1,c2,c3,c4;
  78.     var returntext="";
  79.     var inelastic = gid('inelastic').checked;
  80.     for(c1=minweights[0]; c1<(maxweights[0]+1); c1++){
  81.     for(c2=minweights[1]; c2<(maxweights[1]+1); c2++){
  82.         if(!inelastic||inelastic&&(((c1/c2)<0.5)||((c1/c2)>2))){
  83.     for(c3=minweights[2]; c3<(maxweights[2]+1); c3++){
  84.         if(!inelastic||inelastic&&(((c3/c2)<0.5)||((c3/c2)>2))){
  85.     for(c4=minweights[3]; c4<(maxweights[3]+1); c4++){
  86.         if(!inelastic||inelastic&&(((c3/c4)<0.5)||((c3/c4)>2))){
  87.         cyclelength=0;
  88.        
  89.         s[0]=4900-frictions[0];
  90.         s[1]=outputspeed(s[0],c1,c2,frictions[1]);
  91.         s[2]=outputspeed((s[1]),c2,c3,frictions[2]);
  92.         s[3]=outputspeed((s[2]-1000),c3,c4,frictions[3]);
  93.         if(s[2]<1){break;}
  94.         if(s[3]<1){break;}
  95.         s[4]=4900-frictions[4];
  96.         s[5]=outputspeed((s[4]),c4,c3,frictions[3]);
  97.         s[6]=outputspeed((s[5]),c3,c2,frictions[2]);
  98.         s[7]=outputspeed((s[6]-1000),c2,c1,frictions[1]);
  99.         if(s[6]<1){break;}
  100.         if(s[7]<1){break;}
  101.         cyclelength += ( s[6]<(s[0]-s[7]-frictions[1]) ? 1 : 1+mceil( (s[6]-(s[0]-s[7]-frictions[1]) )/s[1] ) );
  102.         cyclelength += mceil(50000/s[2]) + ((mceil(100000/(s[5]-frictions[3]+frictions[2])) < mceil(50000/s[2])) ? 1 : 0);
  103.         cyclelength += mceil(100000/s[3]);
  104.        
  105.         cyclelength += ( s[2]<(s[4]-s[3]-frictions[3]) ? 1 : 1+mceil( (s[2]-(s[4]-s[3]-frictions[3]) )/s[5] ) );
  106.         cyclelength += mceil(50000/s[6]) + ((mceil(100000/(s[1]-frictions[1]+frictions[2])) < mceil(50000/s[6])) ? 1 : 0);
  107.         cyclelength += mceil(100000/s[7]);
  108.         cyclelength--;
  109.         cyclelength--;
  110.         if((limiter==false)||(limiter==cyclelength)||((limiter-1)==cyclelength)){
  111.         returntext+=cyclelength + " : " + c1 + " " + c2 + " " + c3 + " " + c4 + " \n";
  112.         }
  113.        
  114.     }}
  115.     }}
  116.     }}
  117.     }
  118.     gid("js-output").value = returntext;
  119.     gid('timetaken').innerText=("Calculated! Took " + ((Date.now()-rn)/1000 ) + " seconds.");
  120. }
  121.  
  122.  
  123.     </script>
  124. </body>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top