http://qs321.pair.com?node_id=11145635


in reply to Re: Challenge: sort weekdays in week-order (elegantly and efficiently)
in thread Challenge: sort weekdays in week-order (elegantly and efficiently)

The latter: some kind of algorithm or rather a transform of each weekday into a new name which is alphabetically sorted right (as per the %order or whatever calendar order). For example, transform each weekday by removing the 1st letter, then their cmp order is correct. OK this does not work. But I was looking for this kind of transform. Of course I can try exhaustively find such transform with random masks on the weekday bytes.

monday:011011010110111101101110011001000110000101111001 tuesday:01110100011101010110010101110011011001000110000101111001 wednesday:011101110110010101100100011011100110010101110011011001000110 +000101111001 thursday:0111010001101000011101010111001001110011011001000110000101111 +001 friday:011001100111001001101001011001000110000101111001 saturday:0111001101100001011101000111010101110010011001000110000101111 +001 sunday:011100110111010101101110011001000110000101111001

(with this:

for (qw/monday tuesday wednesday thursday friday saturday sunday/){ print $_ .':'. join('', map { sprintf "%08b", ord($_) } split(//, lc +$_))."\n"; }
)