WESun Puzzle Challenge given November 15, 2003:

Take letters in
stolichnaya
rearrange for two words
that are opposites.

-- WESun Puzzle, 2003-11-15

My strategy is to canonicalize and compare in that space. First, a helper and some data.

sub canon {
	my $v=shift;
	$v =~ s/\W//; # remove non-word chars
	# lc join '', sort split '',   $v  # ERROR! Uri found it.
	     join '', sort split '', lc $v # Must lc before sort
}
BEGIN { 
	$master='aachilnosty'; # = canon lc 'STOLICHNAYA'
	$partial_pat=qr/^a{0,2}c?h?i?l?n?o?s?t?y?$/; 
}

First cut, anything that isn't even vaguely the right stuff can be skipped, then check if it fits correctly.

next unless /^[STOLICHNAYA]+$/i;
my ($word, $letters)=($_, canon($_));
next unless $letters =~ $partial_pat;
push @{$words{$letters}},$word ; # autovivfy

Next problem is to compute the difference of the canonic form of the current word and the master, to compute the canonic required to match it.

sub subtract { # letter sequences
	my ($longer, $shorter)=(@_);
	my $difference=$longer;
	foreach my $c (split '', $shorter) {
		$difference =~ s/$c//
			or die "subtract($longer,$shorter) :- can not remove a $c from $difference";
			# This Die is not good design for reuse ...
		}
	return $difference;
}

my $remainder=subtract($master, $letters);

Now, we check if we've already seen the required $remainder. If not, the word matching this word will find it via it's remainder.

next unless exists $words{$remainder};

print "$word ($letters) @{$words{$remainder}} ( $remainder)";

# END { print canon lc 'STOLICHNAYA' }

problem is to compute the difference of the canonic form of the current word and the master, to compute the canonic required to match it.

The first copy of /usr/dict/words I tried found only the following.

lay (aly) Atchison ( achinost)
litany (ailnty) chaos ( achos)
slay (alsy) Antioch ( achinot)
yacht (achty) Alison ( ailnos)

Litany and Chaos are perhapd not quite opposites but are at least quite well separated! But it doesn't feel like what we want. (And 's not the answer desired, either.)

The basic dictionary on my laptop, which was based I thought on the same source and is called by the same name, has only

hasty (ahsty) alnico ( acilno)


Whereas a larger dictionary from National Puzzle League (enable1) finds a slew, including all the above and the desired

satanic (aacinst) holy ( hloy)

plus

nachos (achnos) laity ( ailty)
oilcan (acilno) hasty ( ahsty)
saintly (ailnsty) chao ( acho)

The Webster's 2nd word-list web2 has quite a few more.

I haven't checked what we get with Upper-case words with the corrected canon() yet ...

Email

script (text)

I tried re-writing the script (text) to save the hash to a file instead, to trade time for space, but it still hangs on my laptop.