[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[FWP] Love & Hate shenanigans




The following are valid perl statements using boolean functions:

print "jas" || "root";
print "up"  && "down";

However, they aren't very interesting because since we're comparing
non-empty strings, || will always return the first, and && will always
return the second.  However, perl also has a binary 'or' and 'and'
operators (often used inadvertently by programmers that mean to use
the boolean functions above).  For some very special words and order,
however, the two respective operators "||" and "|", and "&&" and "&"
give the same result.  I call these special pairs of words, "Bulleans"
for the obvious reason.

Fr'instance, 

print "love" & "hate";  # Hate if you want both
print "love" | "hate";  # Love if you have a choice
print "good" & "bad";   # Badness overwhelms

The challenge is to write some perl, that looks through a list of
words and prints pairs of Bulleans.

A good par is 78 strokes.  But this is rather memory hungry and I look
forward to better solutions - its not a difficult problem...more so
that the resulting word lists would be fun (to use?).

perl -e'chomp(@_=<>);map{$c=$_;map{print"$c $_\n"if!($_ eq$c)&&(($_&$c)eq$_)}@_}@_'


An interesting aside: 
1. Bulleans are commutative.

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe