<div dir="ltr">Chris, and all.. Since you posted yours, I post this for your pleasure.  I couldn't figure out what you were doing.<br><div><br>#!/usr/bin/env python<br><div class="gmail_quote"><div dir="ltr"><div class="gmail_extra">
<br>"""<br>This is a puzzle brought up on the python mailing list.<br>The goal is to take 3 bits and invert them using boolean logic, but restricted to only 2 NOT gates<br>
Here is a solution I found via google:  <a href="http://www.thelowlyprogrammer.com/2008/05/not-puzzle-solution.html" target="_blank">http://www.thelowlyprogrammer.com/2008/05/not-puzzle-solution.html</a><br>"""<br>
<br>def invert_three(a,b,c):<br>
<br>    """ give three boolean values, return their inverted values<br>    Only 2 NOT operators are allowed<br>    Deduce these truths<br>    """<br>    all_ones = a and b and c<br>    two_or_three = (a and b) or (a and c) or (b and c)<br>

    zero_or_one = not two_or_three<br>    one_one = zero_or_one and (a or b or c)<br>    zero_or_two = not (all_ones or one_one)<br>    zero_ones = zero_or_one and zero_or_two<br>    two_ones = zero_or_two and two_or_three<br>

    <br>    # the output is true if all the inputs are zero, or if one of the inputs is zero and it is either b or c<br>    # or two inputs are zero and they are b and c<br>    # ditto for other two inputs<br>    x = zero_ones or (one_one and (b or c)) or (two_ones and (b and c))<br>

    y = zero_ones or (one_one and (a or c)) or (two_ones and (a and c))<br>    z = zero_ones or (one_one and (b or a)) or (two_ones and (b and a))<br>    return int(x), int(y), int(z)<br>    <br>if __name__ == "__main__":<br>

    for a in range(2):<br>        for b in range(2):<br>            for c in range(2):<br>                print "Input: ", a, b, c, <br>                x, y, z = invert_three(a,b,c)<br>                print "Output: ", x, y, z<br clear="all">

</div></div></div><br clear="all"><br>-- <br><div dir="ltr"><div>Joel Goldstick<br></div><a href="http://joelgoldstick.com" target="_blank">http://joelgoldstick.com</a><br></div>
</div></div>