Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: min and mindex

by jaredor (Priest)
on Nov 08, 2012 at 08:28 UTC ( #1002832=note: print w/replies, xml ) Need Help??

in reply to min and mindex

Y'all are messing with my PerlMonks drinking game: No one said Schwartzian transform, e.g.,

#!/usr/bin/env perl use Modern::Perl; my ($c, $d, $i) = ([qw(7 5 3 0 9 18 12)], [qw(a b c d e f g)], 0); say $d->[[(sort {$a->[0]<=>$b->[0]} map {[$_,$i++]} @{$c})]->[0][1]];

Replies are listed 'Best First'.
Re^2: min and mindex
by kcott (Bishop) on Nov 09, 2012 at 06:13 UTC

    ++ I like your thinking, jaredor!

    So, what's the rules of this drinking game? No doubt I lost points when I failed to utter the incantantion "Schwartzian transform" while coding:

    my $min_pos = ( sort { $a->[0] <=> $b->[0] } map { [$_ => ++$pos] } @array1 )[0]; # do useful stuff print ... $array2[$min_pos->[1]]

    OK, I've downed a large Scotch. Your turn. :-)

    -- Ken

      Wait, what?!

      *I* don't get to drink because you didn't say the magic words, but *you* do? I need to rethink the rules to this game....

      ... but then it is a technical fault that I didn't grok that at the core of your masterful schooling on question posting, problem analysis and solution testing was The Schwartzian ... so okay, I owe you a point or a pint, whichever you prefer.

      Actually, you caught me in a minor sin, since I think "reduce" (++tinita) would be what I would use for the problem as stated (sort of like spinning a log on a lathe to get a toothpick). So I posted an answer which wasn't a great answer for the question, but allowed me to be a wee bit cheeky for my own amusement.

      The "drinking game" is just something I do to keep myself engaged with the site content and is just a variant of what some people do to keep awake in meetings: See if you can predict a response. Successful prediction? Assess whether it was necessary or gratuitous. Gratuitous? Point! Take a drink. For PM my rubric is

      1. Is the answer not wrong, but not quite right?
      2. Could the answer have been relatively easy to demonstrate with code, but wasn't?
      3. Does the answer seem to be more of an homage to the hive mind rather than a sincere effort to educate or illuminate?

      (Now you see why I felt compelled to add working code to my snarky comment.)

      This game is not for everyone: According to a thread I read a while back, sundialsvc4 would have destroyed BrowserUK's liver years ago. ;-)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1002832]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2021-01-25 00:50 GMT
Find Nodes?
    Voting Booth?