Logic problem: need better logic for desired thruth table.

Skybuck Flying skybuck2000 at hotmail.com
Thu May 28 17:50:00 EDT 2015


Hello,

I was just coding and ran into a little logic problem which is as follows:

There are two booleans/variables which can be either false or true.

The desired thrutle table is:

A = input
B = input
C = output

A B C:
-------
F F T
F T F
T F T
T T T

Surpisingly enough I don't think there is a casual/common operator for this 
thruth table.

AND does not apply.
OR does not apply.
XOR does not apply.

So I would need some combined operators to give the desired result.

I tried logic below... but funny enough it failed, now I feel like a noob 
lol and share this funny little fail logic with you.

Can you improve/fix the logic ?

This is python code, but this^ logic/thruth table problem basically applies 
to any programming language:

# loop has to run if:
# while DesiredResult==True:
# Desired truth table for BotWaitForCooldown and CooldownDetected
# BotWaitForCooldown:  CooldownDetected: Desired Result:
# False       False    True
# False       True     False
# True     False    True
# True     True     True
# desired/suiting logic:
# (BotWaitForCooldown or ((not BotWaitForCooldown) and CooldownDetected))

def TestLogic( BotWaitForCooldown, CooldownDetected ):
return BotWaitForCooldown or ((not BotWaitForCooldown) and CooldownDetected) 
# this logic is flawed, please improve logic.

if TestLogic( False, False ) == True:
print "test 1 ok"
else:
print "test 1 failed"

if TestLogic( False, True ) == False:
print "test 2 ok"
else:
print "test 2 failed"

if TestLogic( True, False ) == True:
print "test 3 ok"
else:
print "test 3 failed"

if TestLogic( True, True ) == True:
print "test 4 ok"
else:
print "test 4 failed"

Bye,
  Skybuck. 




More information about the Python-list mailing list