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"; }

Replies are listed 'Best First'.
Re^3: Challenge: sort weekdays in week-order (magical formula)
by LanX (Sage) on Jul 21, 2022 at 15:44 UTC
    Honestly, I find those magical formulas░ always too voodoo.

    From a maintenance point of view they are horrible, because they don't scale well with new requirements.

    Even Doomsday fails if you go back before Gregorian calendar

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

    ░) don't know the correct term here... │


    there is only a limited number of orders 7!

    so you could try a brute force search composing formulas based on inputs like substrings or word-length.

    I'm still not sure if the solution will be shorter than just a clever list.▓


    ▓) tybaldt's solution with "motuwethfrsasu" is just an example of such a clever list.

    │) kind of golfing, isn't it?