Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>SCAN</title>
- </head>
- <script type="text/javascript">
- function scan(check_val){
- var queue = [70,123,236,596,403,403,60,414,328,140,26,336,42,16,162,99,226,174,487,135,443,206,272,485,209,138,552,102,486,9,275,560,34,100,98,520,339,259,594,82,523,157,481,18,410,371,92,317,262,198];
- var sorted_l=[];
- var sorted_r=[];
- var hops=0;
- var movement=0;
- var sorted = queue.sort(function(a,b){return a-b});
- var min = Math.min.apply(Math, sorted);
- var max = Math.max.apply(Math, sorted);
- var random = Math.floor((Math.random() * (max-min)+min));
- alert('Scanning for value: '+check_val.value+'...');
- alert('Our starting location will be: '+random+'.');
- var i=0;
- while(i<sorted.length){
- if(sorted[i] < random){
- sorted_l.push(sorted[i]);
- }else{
- sorted_r.push(sorted[i]);
- }
- i++;
- }
- //go to left side
- var last_hop = random;
- alert('Left side:'+sorted_l.toString());
- alert('Right side:'+sorted_r.toString());
- var i = sorted_l.length - 1;
- while(i>=0){
- hops +=1;
- var temp = parseInt(Math.abs(last_hop - sorted_l[i]));
- movement = parseInt(movement + temp);
- if(sorted_l[i] == check_val.value){
- alert(sorted_l[i]+' in '+hops+' hops, moved: '+movement);
- return(true);
- }
- last_hop = sorted_l[i];
- i--;
- }
- //go to right side
- var last_hop2 = random;
- var i=0;
- while(i<=sorted_r.length-1){
- hops +=1;
- var temp2 = parseInt(Math.abs(last_hop2 - sorted_r[i]));
- movement = parseInt(movement + temp2);
- if(sorted_r[i] == check_val.value){
- alert(sorted_r[i]+' in '+hops+' hops, movement '+movement);
- return(true);
- }
- last_hop2 = sorted_r[i];
- i++;
- }
- alert("failed to find value after "+hops+" hops and moved "+movement);
- return(false);
- }
- </script>
- <body>
- <button type="button" action="" type="submit" onclick="scan(this)" value="258">Scan</button>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement