Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: noGolf: Fuzzy finder / autocomplete

by Discipulus (Canon)
on Jun 23, 2015 at 08:50 UTC ( [id://1131585]=note: print w/replies, xml ) Need Help??


in reply to Golf: Fuzzy finder / autocomplete

ah! i saw this last night and i started mumbling around a lot of permutations of regexes.. but my brain was too little to afford it.
Then, before sleeping, a simpler solution (regex based) come to my mind.
I'm not a Perl golfer at all and i cant even read the proposed solution: so i answer to the challenge part of the question. Anyway my Perl tends to be unreadable, so my simple solution is quite obfu..

But, in the example you gave using the 'mig' pattern, Corion, the resulting ranking of choices ( migrations django_migrations main_generator django_admin_log ) is equal to the last one in the python example, but i dont understand why 'django_migrations' comes before 'main_generator': maybe i'm wrong but in my mind 'shortest leftmost' means 'leftmost shortest' and this is the normal way to order strings..

Here is my nine lines (of relevant code) solution, using plain Perl (i'm sure it can be shortened and golfed a lot..). It handles also the correct order of similar words:
#!perl use strict; use warnings; @ARGV=qw(mig main_generator migrations django_migrations django_admin_ +log myfoo\bar.txt main_generatorZ XXX xxx); my $patt = shift; my $rx = (map {qr/$_/} join '', (map { '([^'.$_.']*)(?:'.$_.')'} $patt +=~/./g ))[0] ; my %r; map { $_=~/$rx/ ? push @{$r{join'_', map{sprintf "%02d",length $_} $_=~/$rx/g}},$_ : push @{$r{join'_', map{'99'} 1..length $patt}} ,$_ }@ARGV; print map { join ' ', sort @{$r{$_}},"\n" } sort keys %r; __OUT__ migrations main_generator main_generatorZ django_migrations django_admin_log XXX myfoo\bar.txt xxx

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2024-04-24 17:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found