daily pastebin goal
63%
SHARE
TWEET

Untitled

a guest Oct 21st, 2018 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?
  2. $data = array(2,4,6,3,5,7,10,9,8,1,0);
  3. $n = 0;
  4. // assign
  5. $maxmin = array($data[0],0,$data[0]);
  6. //--------------------
  7. // first compare
  8. //--------------------
  9. $i=1;
  10. $max = $maxmin[0];
  11. $min = $maxmin[2];
  12. $gap = $max - $min;     //gap between max and min
  13. $gapmax = $max - $data[$i]; //gapmax between max and data
  14. $gapmin = $min - $data[$i]; //gapmin between min and data
  15. //if abs| gapmax + gapmin | > $diff then it will be max or min
  16. if(sqrt(pow($gapmax+$gapmin,2))>$gap){ 
  17.     //select index to determine max or min value
  18.     $index = ($gapmax+$gapmin)/sqrt(pow($gapmax+$gapmin,2))+1; 
  19.     $maxmin[$index] = $data[$i];
  20. }
  21. //--------------------
  22. // second compare
  23. //--------------------
  24. $i++;
  25. $max = $maxmin[0];
  26. $min = $maxmin[2];
  27. $gap = $max - $min;     //gap between max and min
  28. $gapmax = $max - $data[$i]; //gapmax between max and data
  29. $gapmin = $min - $data[$i]; //gapmin between min and data
  30. //if abs| gapmax + gapmin | > $diff then it will be max or min
  31. if(sqrt(pow($gapmax+$gapmin,2))>$gap){ 
  32.     //select index to determine max or min value
  33.     $index = ($gapmax+$gapmin)/sqrt(pow($gapmax+$gapmin,2))+1; 
  34.     $maxmin[$index] = $data[$i];
  35. }
  36. //--------------------
  37. // third compare
  38. //--------------------
  39. $i++;
  40. $max = $maxmin[0];
  41. $min = $maxmin[2];
  42. $gap = $max - $min;     //gap between max and min
  43. $gapmax = $max - $data[$i]; //gapmax between max and data
  44. $gapmin = $min - $data[$i]; //gapmin between min and data
  45. //if abs| gapmax + gapmin | > $diff then it will be max or min
  46. if(sqrt(pow($gapmax+$gapmin,2))>$gap){ 
  47.     //select index to determine max or min value
  48.     $index = ($gapmax+$gapmin)/sqrt(pow($gapmax+$gapmin,2))+1; 
  49.     $maxmin[$index] = $data[$i];
  50. }
  51. //--------------------
  52. // 4th compare
  53. //--------------------
  54. $i++;
  55. $max = $maxmin[0];
  56. $min = $maxmin[2];
  57. $gap = $max - $min;     //gap between max and min
  58. $gapmax = $max - $data[$i]; //gapmax between max and data
  59. $gapmin = $min - $data[$i]; //gapmin between min and data
  60. //if abs| gapmax + gapmin | > $diff then it will be max or min
  61. if(sqrt(pow($gapmax+$gapmin,2))>$gap){ 
  62.     //select index to determine max or min value
  63.     $index = ($gapmax+$gapmin)/sqrt(pow($gapmax+$gapmin,2))+1; 
  64.     $maxmin[$index] = $data[$i];
  65. }
  66. //--------------------
  67. // 5th compare
  68. //--------------------
  69. $i++;
  70. $max = $maxmin[0];
  71. $min = $maxmin[2];
  72. $gap = $max - $min;     //gap between max and min
  73. $gapmax = $max - $data[$i]; //gapmax between max and data
  74. $gapmin = $min - $data[$i]; //gapmin between min and data
  75. //if abs| gapmax + gapmin | > $diff then it will be max or min
  76. if(sqrt(pow($gapmax+$gapmin,2))>$gap){ 
  77.     //select index to determine max or min value
  78.     $index = ($gapmax+$gapmin)/sqrt(pow($gapmax+$gapmin,2))+1; 
  79.     $maxmin[$index] = $data[$i];
  80. }
  81. //--------------------
  82. // 6th compare
  83. //--------------------
  84. $i++;
  85. $max = $maxmin[0];
  86. $min = $maxmin[2];
  87. $gap = $max - $min;     //gap between max and min
  88. $gapmax = $max - $data[$i]; //gapmax between max and data
  89. $gapmin = $min - $data[$i]; //gapmin between min and data
  90. //if abs| gapmax + gapmin | > $diff then it will be max or min
  91. if(sqrt(pow($gapmax+$gapmin,2))>$gap){ 
  92.     //select index to determine max or min value
  93.     $index = ($gapmax+$gapmin)/sqrt(pow($gapmax+$gapmin,2))+1; 
  94.     $maxmin[$index] = $data[$i];
  95. }
  96. //--------------------
  97. // 7th compare
  98. //--------------------
  99. $i++;
  100. $max = $maxmin[0];
  101. $min = $maxmin[2];
  102. $gap = $max - $min;     //gap between max and min
  103. $gapmax = $max - $data[$i]; //gapmax between max and data
  104. $gapmin = $min - $data[$i]; //gapmin between min and data
  105. //if abs| gapmax + gapmin | > $diff then it will be max or min
  106. if(sqrt(pow($gapmax+$gapmin,2))>$gap){ 
  107.     //select index to determine max or min value
  108.     $index = ($gapmax+$gapmin)/sqrt(pow($gapmax+$gapmin,2))+1; 
  109.     $maxmin[$index] = $data[$i];
  110. }
  111. //--------------------
  112. // 8th compare
  113. //--------------------
  114. $i++;
  115. $max = $maxmin[0];
  116. $min = $maxmin[2];
  117. $gap = $max - $min;     //gap between max and min
  118. $gapmax = $max - $data[$i]; //gapmax between max and data
  119. $gapmin = $min - $data[$i]; //gapmin between min and data
  120. //if abs| gapmax + gapmin | > $diff then it will be max or min
  121. if(sqrt(pow($gapmax+$gapmin,2))>$gap){ 
  122.     //select index to determine max or min value
  123.     $index = ($gapmax+$gapmin)/sqrt(pow($gapmax+$gapmin,2))+1; 
  124.     $maxmin[$index] = $data[$i];
  125. }
  126. //--------------------
  127. // 9th compare
  128. //--------------------
  129. $i++;
  130. $max = $maxmin[0];
  131. $min = $maxmin[2];
  132. $gap = $max - $min;     //gap between max and min
  133. $gapmax = $max - $data[$i]; //gapmax between max and data
  134. $gapmin = $min - $data[$i]; //gapmin between min and data
  135. //if abs| gapmax + gapmin | > $diff then it will be max or min
  136. if(sqrt(pow($gapmax+$gapmin,2))>$gap){ 
  137.     //select index to determine max or min value
  138.     $index = ($gapmax+$gapmin)/sqrt(pow($gapmax+$gapmin,2))+1; 
  139.     $maxmin[$index] = $data[$i];
  140. }
  141. //--------------------
  142. // 10th compare
  143. //--------------------
  144. $i++;
  145. $max = $maxmin[0];
  146. $min = $maxmin[2];
  147. $gap = $max - $min;     //gap between max and min
  148. $gapmax = $max - $data[$i]; //gapmax between max and data
  149. $gapmin = $min - $data[$i]; //gapmin between min and data
  150. //if abs| gapmax + gapmin | > $diff then it will be max or min
  151. if(sqrt(pow($gapmax+$gapmin,2))>$gap){ 
  152.     //select index to determine max or min value
  153.     $index = ($gapmax+$gapmin)/sqrt(pow($gapmax+$gapmin,2))+1; 
  154.     $maxmin[$index] = $data[$i];
  155. }
  156.  
  157. $result = ($maxmin[2]+$maxmin[0])/2;
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