Logic problem: need better logic for desired thruth table.

Mark Lawrence breamoreboy at yahoo.co.uk
Thu May 28 18:56:11 EDT 2015


On 28/05/2015 23:39, Lew Pitcher wrote:
> On Thursday May 28 2015 17:50, in comp.lang.c, "Skybuck Flying"
> <skybuck2000 at hotmail.com> 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
>
> Seems simple enough: C == A || !B
>
> 18:38 $ cat testlogic.c
> #include <stdio.h>
> #include <stdlib.h>
>
> /*
> ** A = input
> ** B = input
> ** C = output
> **
> ** A B C:
> ** -------
> ** F F T
> ** F T F
> ** T F T
> ** T T T
> */
>
> int testlogic(int a, int b)
> {
>    return (a || !b);
> }
>
> int main(void)
> {
>                        /* A B C */
>    int ttable[4][3] = {  {0,0,1},        /* F F T */
>                          {0,1,0},        /* F T F */
>                          {1,0,1},        /* T F T */
>                          {1,1,1}         /* T T T */
>                       };
>    int rc = EXIT_SUCCESS;
>    int i, max;
>
>    for (i = 0, max = sizeof(ttable) / sizeof(ttable[0]); i < max ; ++i)
>      if (testlogic(ttable[i][0],ttable[i][1]) != ttable[i][2])
>      {
>        printf("testlogic failed on test %d\n",i);
>        rc = EXIT_FAILURE;
>      }
>
>    if (rc == EXIT_SUCCESS) puts("SUCCESS");
>
>    return rc;
> }
> 18:39 $ cc -o testlogic testlogic.c
> 18:39 $ ./testlogic
> SUCCESS
>
>

Strangest looking Python I've ever seen.  Or is it a case of "Get thee 
behind me, Satan" :)

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence




More information about the Python-list mailing list