in reply to Re: Pimp my code - Schwartzian transform maybe?
in thread Pimp my code - Schwartzian transform maybe?
Interesting. A little tweaking and we come up with the following which preserves the ordering and priority encoding nature of the original function. Note in particular that the addition is replaced by a bitwise or - that's where the priority encoding bit happens (it is also unaffected by duplicate flags). The bitwise complements preserve the original sort order.
my %flagvalues = ( R => ~(2**1 - 1), T => ~(2**2 - 1), B => ~(2**3 - 1), I => ~(2**4 - 1), F => ~(2**5 - 1), L => ~(2**6 - 1), ); sub flagValue { my $weight = ~(2**7 - 1); for (split //, shift){ $weight |= $flagvalues{$_} if exists $flagvalues{$_}; } return ~$weight; }
|
|---|