Logic problem: need better logic for desired thruth table.

sohcahtoa82 at gmail.com sohcahtoa82 at gmail.com
Thu May 28 17:58:19 EDT 2015


On Thursday, May 28, 2015 at 2:50:18 PM UTC-7, Skybuck Flying wrote:
> 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.

I think the logic you're really looking for is:

return BotWaitForCooldown or (not (BotWaitForCooldown or CooldownDetected))



More information about the Python-list mailing list