• (nodebb)

    It's almost as if

        laborService[i].Order = (i - half) + 1;
    

    should be

        laborService[i].Order = 2*(i - half) + 1;
    

    in which case it would, indeed, be an interleaver.

  • (nodebb)

    The hard part to see is what the wider point of this code is, even if it was an interleaver. Why would anyone actually need to reorder LaborServices like that?

  • NoOne (unregistered)

    Bonus points for the author to call out "tranposition" but writing about a "C# fuction" themselves.

  • Me (unregistered)

    QuickSort?

  • Jonathan (unregistered)

    fuction?

  • (nodebb) in reply to dkf

    Why would anyone actually need to reorder LaborServices like that?

    I have no idea.

  • D J Hemming (unregistered) in reply to NoOne

    Or perhaps they refer to it as a "fuction" as a humorous riff on the typo of Tranpose...

  • (nodebb) in reply to NoOne

    I think 'fuction' is probably the best description of that piece of code.

  • MiserableOldGit (unregistered)

    Could be something to do with pagination, printing evens then odds, assuming a device that prints/engraves/scans/craps on a stack of media one side at a time, then does the other side. Although you'd expect one half to be in reverse order then, probably.

    Unless we discover what calls it we'll never really know. either, seems a bit of a cack-handed way to do it.

  • Naomi (unregistered) in reply to D J Hemming

    Or perhaps they refer to it as a "fuction" as a humorous riff on the typo of Tranpose...

    The fact that '"fuction"' is quoted in the original article seems to suggest this, doesn't it?

  • David Green (github)

    It looks like an algorithm to find the firing pattern for the eight cylinders of a 1969 Plymouth.

  • Shiwa (unregistered)

    Am I the only one annoyed by the if/else inside the for loop ? Looping on one half, then on the other, would be more efficient and readable (it would still make no sense, though).

  • (nodebb)

    This looks like a bad attempt of "For homework, write a program that uses a Merge Sort routine" and was written in the 5 minutes between classes on the day it was due. It sorta sorts, and it merges the list with exquisite WTFery, right?

  • rfportilla (unregistered)

    I feel like I have written a lot of "fuctions" over the years.

  • (nodebb)

    if it's position is less than half

    *its

  • Long Time Lurker (unregistered)

    A true What The Fuction

  • scriptninja (github)

    I find the fact that the order appears to have been added specifically in order to do this kind of telling, actually. My guess is that this is someone's about 1/8 completed progress towards something that was never finished - this was a checkpoint with a minimal-effort placeholder for the math, they left to go look up the correct math or maybe the correct spelling of "transpose" - or perhaps what the word was they were trying to remember that actually described what they were doing, which was not transpose - and never got back to it.

    I have no strong evidence for this hypothesis but I am inordinately fond of it.

  • seebs (unregistered)

    This feels a bit like a half-baked attempt to do something based on a heap, where the items "under" node n would be at 2n and 2n+1, but it doesn't actually do that.

  • (nodebb)

    This looks like a (broken) implementation of a Faro shuffle, but it missed the mark. At least it is not throwing away any data. On my first reading during BC (before coffee), I was thinking it was setting the element of the original list to the positions in the resulting list, which would have overwritten element and left gaps. Thankfully, it just set the Order member and sorted on that to get a different ordering.

    Still, these are LabourServices, not playing cards, so why try a Faro shuffle on them? Trying to mix us scheduling or something?

    Addendum 2020-11-10 12:03: Oops, mix UP scheduling...

  • Gallowglass (unregistered)

    its like shuffling cards. In real life when you shuffle you never get the cards perfectly interleaved so this perfectly represents the partial interleaving of an actual physical shuffle. Now call it three, four times in a row and you've created a manual card shuffle. It's brilliant*.

  • WTFGuy (unregistered)

    My thought is its a defective attempt at a fair share algorithm. The business use case is something like a government website showing a roster of LaborServices to would-be job seekers. But the site cannot show favoritism between the services and therefore needs to show each successive pageview the same list of e.g. 8 items but in a different order.

    The dev thought truly random would be too hard, or not provably "fair" to the PHBs. So they went for some sort of a shuffle. Which they duly fouled up.

    it would be interesting to look at the wider app to see if the persistence layer saves the updated order field back to the backing store or if the results of a run of this function are saved and used as input to the next run.

  • Swamp Thang (unregistered) in reply to thosrtanner

    I'm pretty sure you'd still need to remove the "i" for that to be the case.

  • (nodebb) in reply to scriptninja

    It does read like some sort of stream-of-consciousness thing; the way half is calculated is less real-world code and more a peek into someone's thought processes.

  • Worf (unregistered) in reply to WTFGuy

    Of course, if it was a fair share thing, rather than shuffling, I'd just do it in a round-robin way where the second element of the list before is now the top element of the list now, and the top of the list before is at the bottom of the list now. That way they all have their time at the top equally.

    Of course, one needs to consider the possibility that an option gets removed and you might accidentally skip two ahead, but without the requirements, that consideration may be moot to begin with.

  • guest (unregistered) in reply to dkf

    I once saw someone create a producer/consumer model where id's with alternate starting-letters went to different consumers (e.g.: consumer 1 did a/c/e/g/... and 2 did b/d/f/h/...). Maybe they were going for something like that? Admittedly it's stupid...

  • Massey (unregistered)

    I have to agree with MiserableOldGit. Probably intended to do interleaving for pagination but they messed it up the first go around and never came back to it.

  • Dave (unregistered) in reply to NoOne

    Bonus points for the author to call out "tranposition" but writing about a "C# fuction" themselves.

    Now that's fuct up.

  • (nodebb)

    You can see the interleaving as a special case of transposition; write n entries into a 2×(n/2) in LR-TD order and then read them back in TD-LR order.

  • WTFGuy (unregistered)

    While we're poking fun at "tranposition"s and "fuction"s there is another issue to pick at. Unlike many WTFs we review, this dev doesn't have any repeated and therefore unnecessary code. Not so our friend and host @Remy whose Department of Redundancy Department is alive and well:

    Now, based on the name, we can assume this was inspired by a matrix transposition- oh, I'm sorry, tranposition- based on the method name.

    ;)

  • nasch (unregistered) in reply to Gallowglass

    Most people don't, but some professional casino dealers actually do perfectly interleave the cards when shuffling.

Leave a comment on “Tranposing the Key”

Log In or post as a guest

Replying to comment #:

« Return to Article