Idempotent partition around median of 5?

Era Scarecrow via Digitalmars-d digitalmars-d at puremagic.com
Wed Feb 3 20:26:28 PST 2016


On Thursday, 4 February 2016 at 02:46:42 UTC, Xinok wrote:
> A solution to this problem does exist: Build a tree of if-else 
> branches for all the different possibilities (2^6=64) and 
> hard-code the optimal sequence of swaps. However, this function 
> would be huge so this isn't very practical.

  Yeah that's kinda what i was coming to a conclusion to.

> Ideally, we want to minimize the size of the function as much 
> as possible, adding in a few extra swaps if necessary.

  Hmmm if i wrote it (this way) it would probably brute force the 
proper way to build the function rather than doing it by hand 
myself. So a helper function to make the optimal if/else 
statements to deal with it.

  BUT this only makes sense if it's always going to be 5 elements, 
if it's fewer or more, then it's sorta pointless and a more 
generic algorithm would be preferred.

  Although writing a brute force program creation helper function 
could still be of some use.


More information about the Digitalmars-d mailing list