Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: sort of misunderstanding of sort

by bliako (Monsignor)
on Mar 21, 2023 at 12:56 UTC ( [id://11151098]=note: print w/replies, xml ) Need Help??


in reply to sort of misunderstanding of sort

one iteration more with -1

basically it's like a logical puzzle you have to solve with asking a *minimum* number of questions (like "is 1 less than 2?") and (ideally) employing heuristics and the identities that hv mentions. In fact Perl's sort does a good job: perl -le 'my $iters;@a=sort{ $iters++; $a<=>$b }map { int rand 50000 }(1..500); print $iters' 3852 whereas an exhaustive sort would ask 500*499/2=124750 questions. So Do What I Mean and Don't @&*%$ Ask Me More Questions Than Necessary hehe

Here is another way to irritate Perl's sort: perl -le 'my$iters;@a=sort{ $iters++;print qq($a $b); [-1,0,1]->[int rand 3] }map { int rand 50000 }(1..500); print $iters'

Edit: see Acme::ICan for another kind of sort

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-03-28 22:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found