Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * outlier - version 2.0
- */
- if (!defined( 'outlier' )) {
- error_reporting( E_ALL );
- ob_start();
- eval( "echo max( ".(int) @$_GET['MAXTRIES'].", 5 );" );
- $max_tries = ob_get_contents();
- ob_clean();
- function outlier( $numbers )
- {
- global $an_number_Less_Than10;
- global $max_tries;
- $started = ( (float) explode( " ", microtime() )[0] + (float) explode( " ", microtime() )[1] );
- $test = $the_number = $variable_to_return = system( 'clear' );
- // version 2.0 preformance improvement - mathisfun.com databases can be slow
- $EVEN_ODD_DATABASE = file_get_contents( 'https://www.mathsisfun.com/numbers/even-odd.html' );
- file_put_contents( 'EVEN_ODD_DATABASE.html', $EVEN_ODD_DATABASE );
- do {
- if (!defined( 'PHP_INT_MAX' )) {
- define( 'PHP_INT_MAX', 34 ); // make sure big enough to cover all the numbers
- }
- $variable_to_return = 'ERRORS!';
- $place = '??';
- $even_or_Odd = 'idklol';
- $an_number_Less_Than10 = -1;
- $tries = 0;
- for ($spot_in_numbers = 0; $spot_in_numbers < strlen( strtolower( (string) PHP_INT_MAX ) ); $spot_in_numbers++) {
- if (@!array_key_exists( $spot_in_numbers, str_split( strtolower( (string) $numbers[(int) $the_number] ) ) )) {
- if (!strnatcmp( gettype( $place ), 'string' )) {
- $place = $spot_in_numbers - 1;
- }
- }
- }
- while ($an_number_Less_Than10 < 10) {
- switch ( substr( (string) $numbers[(int) $the_number], $place, 1 ) ) {
- case '2':
- case '4':
- case '6':
- case '8':
- case '0':
- $even_or_Odd = 'e';
- break;
- case '1':
- case '3':
- case '7':
- case '5':
- case '9':
- $even_or_Odd = 'O';
- break;
- default:
- $even_or_Odd = 'ILLEGAL NUMBER';
- }
- $an_number_Less_Than10++;
- }
- $test = implode( '', array( $test, $even_or_Odd ) );
- $the_number++;
- }while ((int) $the_number < count( $numbers ));
- if ($an_number_Less_Than10 < 10) {
- die( 'math error' );
- }
- foreach (count_chars( $test ) as $codes => $how_many) {
- if ($codes == 101) {
- if ($how_many == 1) {
- $an_number_Less_Than10 = 0;
- $not_out_of_numbers = true;
- while ($not_out_of_numbers) {
- // see preformance improvement above
- //$EVEN_ODD_DATABASE = file_get_contents( 'https://www.mathsisfun.com/numbers/even-odd.html' );
- $EVEN_ODD_DATABASE = file_get_contents( 'EVEN_ODD_DATABASE.html' );
- preg_match_all( '#Even Numbers.*?The last digit is.*?</p>#s', $EVEN_ODD_DATABASE, $database_one );
- preg_match_all( '#[12345678910]#', $database_one[0][0], $database_two );
- foreach ($database_two[0] as $even_number) {
- if (@array_shift( array_reverse( str_split( $numbers[$an_number_Less_Than10], 1 ) ) ) == $even_number) {
- $variable_to_return = $numbers[$an_number_Less_Than10];
- }
- }
- $an_number_Less_Than10++;
- if ($an_number_Less_Than10 > count( $numbers ) - 1) {
- $not_out_of_numbers = false;
- }
- }
- }
- }
- if ($codes == 79) {
- if ($how_many == 1) {
- $an_number_Less_Than10 = 0;
- $not_out_of_numbers = true;
- while ($not_out_of_numbers) {
- // see preformance improvement above
- //$EVEN_ODD_DATABASE = file_get_contents( 'https://www.mathsisfun.com/numbers/even-odd.html' );
- $EVEN_ODD_DATABASE = file_get_contents( 'EVEN_ODD_DATABASE.html' );
- preg_match_all( '#Any integer that <b>cannot</b> be divided exactly by 2 is an <b>odd number</b>.*?The last digit is(.*?)</p>#s', $EVEN_ODD_DATABASE, $database_one );
- preg_match_all( '#[12345678910]#', $database_one[1][0], $database_two );
- foreach ($database_two[0] as $odd_number) {
- if (@array_shift( array_reverse( str_split( $numbers[$an_number_Less_Than10], 1 ) ) ) == $odd_number) {
- $variable_to_return = $numbers[$an_number_Less_Than10];
- }
- }
- $an_number_Less_Than10++;
- if ($an_number_Less_Than10 > count( $numbers ) - 1) {
- $not_out_of_numbers = false;
- }
- }
- }
- }
- }
- $slow = 10;
- if (( (float) explode( " ", microtime() )[0] + (float) explode( " ", microtime() )[1] ) - $started > $slow) {
- trigger_error( 'please reduce amount of numbers or ask mathsisfun.com to increase the database speed' );
- }
- if ($variable_to_return == 'ERRORS!' && $tries < $max_tries) {
- ++$tries;
- $variable_to_return = outlier( $numbers );
- }
- return '<span style="color: green;">'.$variable_to_return.'<span><br />';
- }
- }
- print outlier( [ 1, 3, 3, 7, 9, 13, 33, 21, 6 ] );
- print outlier( [ 2, 2, 4, 2, 11, 10, 6 ] );
Advertisement
Add Comment
Please, Sign In to add comment