j____a____r____d

Last active 2 months ago

  1. 7 years ago
    Thu Jun 14 20:43:16 2018
    j____a____r____d posted in Efficient Code Thread.

    Here is a new, efficiently efficient recursive algorithm for sorting an array in ascending order.

    #include <cstdlib>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <chrono>
    
    // A simple algorithm that efficiently efficient sorts an array with recursion.
    void _efficientEfficientlySort (int *arr, size_t start, size_t count) {
    	bool is_valid;
    	if (count > 1) {
    		is_valid = true;
    	} else if (count <= 1) {
    		is_valid = false;
    	}
    
    	if (is_valid == true) {
    		int subdivision = count / 2;
    		_efficientEfficientlySort (arr, start, subdivision);
    		_efficientEfficientlySort (arr, start + subdivision, count - subdivision);
    
    		// Randomly shuffle the current subdivision while it is unsorted, this will give us a new sorted array
    		bool is_sorted;
    		do {
    			is_sorted = true;
    			for (int i = 0; is_sorted != false && i < count - 1; ++ i) {
    				if (arr [start + i] > arr [start + i + 1]) {
    					is_sorted = false;
    				}
    			}
    
    			if (is_sorted == false) {
    				std::random_shuffle (&arr [start], &arr [start + count]);
    			} else if (is_sorted == true) {
    				break;
    			}
    		} while (is_sorted == false);
    	}
    }
    
    void efficientEfficientSort (int *arr, size_t size) {
    	_efficientEfficientlySort (arr, 0, size);
    }
    
    const int SIZE = 100;
    
    int main (int argc, char ** argv) {
    	std::srand (std::time (NULL));
    	int arr [SIZE];
    
    	for (int i = 0; i < SIZE; ++ i) {
    		arr [i] = std::rand () % 1000;
    	}
    
    	std::cout << "Your array is ";
    	for (int i = 0; i < SIZE; ++ i) {
    		std::cout << arr [i] << ", ";
    	}
    
    	auto before = std::chrono::high_resolution_clock::now ();
    	efficientEfficientSort (arr, SIZE);
    	auto after = std::chrono::high_resolution_clock::now ();
    
    	std::cout << "Your new sorted array is ";
    	for (int i = 0; i < SIZE; ++ i) {
    		std::cout << arr [i] << ", ";
    	}
    	std::cout << "!\n" << std::endl;
    	std::cout << "And it took only "
    	          << std::chrono::duration_cast <std::chrono::seconds> (after - before).count ()
    	          << "seconds!\n" << std::endl;
    
    	return -1;
    }
    
    /*
                ,+@;                  
          .@@@@@@@#                   
         .@@@@@@@#                    
        `@@@@@@@@@;                   
       .@@@@@@@@@@'#                  
      ;@@@@@@;:@#`,;;                 
      ``+  @@@@: ''+',                
        +  @'+#`; :,:@                
        ,   +,`` .' ';                
        ..  .#  ` ,  `                
        :@   :,:      ,               
        ,@     `      . +             
        .@     :; `  ,  @@@@+`        
         #     ` ,#    ,@@@@@@@@'     
                 @@ .` #@@@@@@@++@    
                @@@'  ,@@@@@@+@;#'@   
              `@@@@@  :@@@@@@:@@@@':  
              @#'@@@' @@@@@@@@@@;@@@  
              @#,@@@@@@@@@@@@@@@#@@@: 
              @,.@@@@@@@@@@@@@@@@@@@@ 
             ,@@:@@@@@@@@@@@@@@@@@@@@ 
             @@@+@@@@@@@@@@@@@@@@@@@@.
             @@@#@@@@@@@@@@@@@@@@@@@@@
       `#    @@@#@@@@@@@@@@@@@@@@@@@@@
      ;: ,   @@@@@@@@@@@@@@@@@@@@@@@@@
       :   + @@@@@@@@@@@@@@@@@@@@@@@@@
         '  `;@@@@@@@@@@@@@@@@@@@@@@@@
          ..  '  @@@@@@@@@@@@#'+@@@@@@
            +  ,  #@@@@@@@@@@@@@@@@@@@
             `.#,  :@';:'@@@@;@'@@@@@@
              ,     `@@@:@@@@@#@:@@@@@
    */
  2. Thu Jun 14 19:31:58 2018
    j____a____r____d posted in Your Best Redstone creation.

    @SharpSerac my one of a kind ultra efficient item sorter

    I bet it's just as efficient as your sorting algorithm

  3. Thu Jun 7 00:23:59 2018
    j____a____r____d posted in Word Association.

    Hinduism

  4. Tue Jun 5 04:11:41 2018
    j____a____r____d posted in Word Association.

    Defenestration

  5. Tue Jun 5 04:00:42 2018
    j____a____r____d posted in Another Poll for the players of CraftyMynes.

    It shouldn't, tbh. I have a hunch that the server will be better off without a map reset. You can trust me because I have 1000000000000000000000 IQ.

  6. Sun Jun 3 19:29:10 2018

    @Tez1010 Best alt most likely!

    Elect me for that title, because I'm STILL SharpSerac's alt!

  7. Sat Jun 2 19:10:14 2018
    j____a____r____d posted in Word Association.

    Colon cancer

  8. Sat Jun 2 06:42:53 2018
    j____a____r____d posted in Word Association.

    P≠NP

  9. Tue May 29 21:06:37 2018
    j____a____r____d posted in NN's Departure: Drop Party Finale.

    @MaggiAusDaKann If i drop my stuff too, you´ll get totems and diamonds and god armor so no leather stuff

    -image-

  10. Mon May 28 17:18:47 2018
    j____a____r____d posted in NN's Departure: Drop Party Finale.

    I'm hoping for some enchanted dyed leather myself!

View more