Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <meta charset="UTF-8"/>
- <head>
- </head>
- <body>
- ▲<br/>
- ║<br/>
- ╚=▲
- <p onChange=estimate()>
- <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/>
- 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/>
- 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/>
- 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/>
- 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/>
- Friction 5<textarea class="js-regexpF5" cols="50" rows="1">10</textarea>
- </p>
- <p>
- <textarea id="js-output" cols="50" rows="10"></textarea><br/>
- <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/>
- </p>
- <script>
- function gid(m){return document.getElementById(m);}
- function qs(n) {return document.querySelector(n);}
- var mfloor = Math.floor;
- var mmin = Math.min;
- var mceil = Math.ceil;
- function outputspeed(inputspeed,inputcartweight,outputcartweight,friction){
- return (mfloor(inputspeed*mmin(1,inputcartweight/outputcartweight))-friction);
- }
- function estimate() {
- var minweights = new Array();
- var maxweights = new Array();
- for(var i=0; i<4; i++){
- minweights[i] = parseInt(qs('.js-regexpm'+(i+1)).value.length > 0 ? qs('.js-regexpm'+(i+1)).value : 0);
- }
- for(var i=0; i<4; i++){
- maxweights[i] = parseInt(qs('.js-regexpW'+(i+1)).value.length > 0 ? qs('.js-regexpW'+(i+1)).value : 0);
- }
- var rv=1;
- for(var i=0;i<4;i++){
- rv=rv*(maxweights[i]-minweights[i]+1);
- }
- gid("js-estimate").value=rv*5.452/60466176;
- }
- function calculate(){
- var rn = Date.now();
- var frictions = new Array();
- var minweights = new Array();
- var maxweights = new Array();
- for(var i=0; i<5; i++){
- frictions[i] = parseInt(qs('.js-regexpF'+(i+1)).value.length > 0 ? qs('.js-regexpF'+(i+1)).value : 0);
- }
- for(var i=0; i<4; i++){
- minweights[i] = parseInt(qs('.js-regexpm'+(i+1)).value.length > 0 ? qs('.js-regexpm'+(i+1)).value : 0);
- }
- for(var i=0; i<4; i++){
- maxweights[i] = parseInt(qs('.js-regexpW'+(i+1)).value.length > 0 ? qs('.js-regexpW'+(i+1)).value : 0);
- }
- var cyclelength=0;
- var cycleforwards=0;
- var cycleback=0;
- var s=new Array();
- var sn=0;
- var limiter = gid('js-regexplimiter').value.length > 0 ? parseInt(gid('js-regexplimiter').value) : false;
- var c1,c2,c3,c4;
- var returntext="";
- var inelastic = gid('inelastic').checked;
- for(c1=minweights[0]; c1<(maxweights[0]+1); c1++){
- for(c2=minweights[1]; c2<(maxweights[1]+1); c2++){
- if(!inelastic||inelastic&&(((c1/c2)<0.5)||((c1/c2)>2))){
- for(c3=minweights[2]; c3<(maxweights[2]+1); c3++){
- if(!inelastic||inelastic&&(((c3/c2)<0.5)||((c3/c2)>2))){
- for(c4=minweights[3]; c4<(maxweights[3]+1); c4++){
- if(!inelastic||inelastic&&(((c3/c4)<0.5)||((c3/c4)>2))){
- cyclelength=0;
- s[0]=4900-frictions[0];
- s[1]=outputspeed(s[0],c1,c2,frictions[1]);
- s[2]=outputspeed((s[1]),c2,c3,frictions[2]);
- s[3]=outputspeed((s[2]-1000),c3,c4,frictions[3]);
- if(s[2]<1){break;}
- if(s[3]<1){break;}
- s[4]=4900-frictions[4];
- s[5]=outputspeed((s[4]),c4,c3,frictions[3]);
- s[6]=outputspeed((s[5]),c3,c2,frictions[2]);
- s[7]=outputspeed((s[6]-1000),c2,c1,frictions[1]);
- if(s[6]<1){break;}
- if(s[7]<1){break;}
- cyclelength += ( s[6]<(s[0]-s[7]-frictions[1]) ? 1 : 1+mceil( (s[6]-(s[0]-s[7]-frictions[1]) )/s[1] ) );
- cyclelength += mceil(50000/s[2]) + ((mceil(100000/(s[5]-frictions[3]+frictions[2])) < mceil(50000/s[2])) ? 1 : 0);
- cyclelength += mceil(100000/s[3]);
- cyclelength += ( s[2]<(s[4]-s[3]-frictions[3]) ? 1 : 1+mceil( (s[2]-(s[4]-s[3]-frictions[3]) )/s[5] ) );
- cyclelength += mceil(50000/s[6]) + ((mceil(100000/(s[1]-frictions[1]+frictions[2])) < mceil(50000/s[6])) ? 1 : 0);
- cyclelength += mceil(100000/s[7]);
- cyclelength--;
- cyclelength--;
- if((limiter==false)||(limiter==cyclelength)||((limiter-1)==cyclelength)){
- returntext+=cyclelength + " : " + c1 + " " + c2 + " " + c3 + " " + c4 + " \n";
- }
- }}
- }}
- }}
- }
- gid("js-output").value = returntext;
- gid('timetaken').innerText=("Calculated! Took " + ((Date.now()-rn)/1000 ) + " seconds.");
- }
- </script>
- </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement