#!/usr/bin/perl use strict; # NPR puzzler helper, 11/23/2003 # Find a pair of words, [X]rn and [X]m, which are antonyms. # We can pull all such pairs from /usr/share/dict/words. open(FH,"/usr/share/dict/words"); my @big_arr; # grep through it the slow way while () { if (/([a-zA-Z]*rn$)/) { push @big_arr, $1; } } #print @big_arr; close FH; # there's got to be a better way to do this. my @solutions; #print "|all_words| = ".$#all_words."\n"; my $curr_word; foreach (@big_arr) { $curr_word = substr($_,0,-2)."m"; my $cmd = 'grep ^'.$curr_word.'$ /usr/share/dict/words'; my $result = `$cmd`; if ($result) { push @solutions, "$_ / $curr_word\n"; } } close FH; print @solutions; #### #!/usr/bin/perl use strict; # NPR puzzler helper, 11/23/2003 # rewritten 12/15/2003 around 4 am. # Find a pair of words, [X]rn and [X]m, which are antonyms. # We can pull all such pairs from /usr/share/dict/words. open(FH,"/usr/share/dict/words"); my (@rn_words, @solutions); @rn_words = grep /([a-zA-Z]*rn$)/, ; chomp(@rn_words); seek FH,0,0; my $ptr = 0; my $this = substr($rn_words[$ptr],0,-2).'m'; LOOP: while () { chomp; next LOOP if ($_ lt $this); if ($_ eq $this) { push @solutions, "$rn_words[$ptr] / $_\n"; } $ptr++; $this = substr($rn_words[$ptr],0,-2).'m'; last unless defined $rn_words[$ptr]; } close FH; print @solutions;