Logic problem: need better logic for desired thruth table.

M Philbrook jamie_ka1lpa at charter.net
Fri May 29 19:07:40 EDT 2015


In article <3794b55678ドルd835419ドルaafe$56138 at news.ziggo.nl>, skybuck2000
@hotmail.com says...
>> 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) 

 First maintain a bit table, something that your code can reference as 
Bools via bit operations..
 In your case it's more less simple..
 
 A combine of 3 bits gives you the value of 7 this this can be used as 
the OR operation
 
 AND operation.
 If value = 7 then.....
 OR Operation.
 If Value <> 0 then....
 Xor Operation, 
 If Value in [1,2,4] then....
 If you need to build the "Value" Product from dangling booleans.
 Value := (Value Shl 1) OR Byte(YourBool); 
 
 Since the compiler only uses the first bit for native booleans this 
works out.
 
 Do the above for all three bools to build a final value..
 Or you can simply mask off a bit as your boolean value from a VALUE
location, which makes it faster in the longrun...
Does that do anything for you ?
Jamie
 


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /