From: KEVIN ZEMBOWER <[EMAIL PROTECTED]>
> I was curious how to implement an algorithm in perl to sort the
> candidates in California's recall ballot. According to the news,
> here's the sort order: RWQOJMVAHBSGZXNTCIEKUPDYFL
> 
> So, for instance, if STDIN is a cat of the file of candidates' names:
> Bock, Audie E. Bustamante, Cruz M. Feinstein, Dan Flynt, Larry
> Kennedy, Edward Thomas Nave, Paul James Novello, Donald A. 
> 
> STDOUT would be the sorted list:
> Bock, Audie E. # Because O comes before U
> Bustamante, Cruz M. 
> Novello, Donald A. # Because O comes before A
> Nave, Paul James 
> Kennedy, Edward Thomas 
> Feinstein, Dan # Because E comes before L
> Flynt, Larry 
> 
> (if I did it correctly).

@list = <DATA>;
chomp for @list;
print join("\n", @list),"\n\n";

tr/RWQOJMVAHBSGZXNTCIEKUPDYFLrwqojmvahbsgzxntciekupdyfl/ABCDEFGHIJKLMN
OPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/ for @list;
print join("\n", @list),"\n\n";

tr/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/RWQOJMVAHBSGZX
NTCIEKUPDYFLrwqojmvahbsgzxntciekupdyfl/ for sort @list;
print join("\n", @list);

__DATA__
Bock, Audie E.
Bustamante, Cruz M.
Feinstein, Dan
Flynt, Larry
Kennedy, Edward Thomas
Nave, Paul James
Novello, Donald A.


Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to