in reply to "Countdown" (golf)
Here's my best solution, at 86 characters: perl -ne'INIT{$l=shift}$r=$L=$l;$r&&=$L=~s/$_//for/./g;$w[$r&&y///c].=$_}{print$w[-1]' That one assumes that there will be at least one match (otherwise it will print the entire word list), and it stores the entire word list in memory.
This next solution avoids both those problems, at the cost of one character. 87 characters: perl -ne'INIT{$l=shift}$r=$L=$l;$r&&=$L=~s/$_//for/./g;$w[y///c].=$_ if$r}{print$w[-1]' Both solutions output all longest matches and work when the set of letters includes duplicates.
Example usage: perl -ne'INIT{$l=shift}$r=$L=$l;$r&&=$L=~s/$_//for/./g;$w[y///c].=$_ if$r}{print$w[-1]' dunscaeyz wordlist
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: "Countdown" (golf)
by blakem (Monsignor) on Dec 01, 2001 at 14:56 UTC |