1

Given the input and the output:

Input     Output
10011100  10010100
10000100  00000000
11111100  10000100
10000011  00000011
10100010  10100010

Are there any operations that can be performed on the rows / cols to get the result? For example, my best try was

((Y AND NOT Y-1) XOR (Y AND NOT Y+1)) OR ((X AND NOT X-1) XOR (X AND NOT X+1))

When no row/col exist, it is assumed to be false. A demonstration of my try:

For Y:

(Y AND NOT Y-1) XOR (Y AND NOT Y+1) =
10011100            00011000         10000100
00000000            00000000         00000000
01111000            01111100         00000100
00000011            00000001         00000010
00100000            10100010         10000010

For X:

(X AND NOT X-1) XOR (X AND NOT X+1) =
10010000            10000100         00010100
10000100            10000100         00000000
10000000            00000100         10000100
10000010            10000001         00000011
10100010            10100010         00000000

OR'ing those 2 results:

((Y AND NOT Y-1) XOR (Y AND NOT Y+1)) OR ((X AND NOT X-1) XOR (X AND NOT X+1))
10010100
00000000
10000100
00000011
10000010

As you can see, it is almost identical as the output, but the COL 3, ROW 5 is 0 instead of 1. Is there any way I can do other operation to take that bit into account?

Thanks in advance.

4

1 回答 1

1

I use the following notation for the position of the bits.

 B
CAD
 E

This gives me a 2^5 possibilities (32) which I write down. I found 3 cases out of all the possibilities where A is 1 but the output must be 0. I could of written down the Karnaugh table, but since I've got only 3, I do a direct function:

IsZero = (!A | ((B & A & E & !C & !D) | (C & A & D & !E & !B) | (A & B & C & D & E)))

If you need IsOne, it is simply !IsZero.

C# code to verify this follows:

class Program
{
    static void PrintFunction(int[,] myArray, int yMax, int xMax)
    {
        for (int y = 0; y < yMax; y++)
        {
            for (int x = 0; x < xMax; x++)
            {
                Console.Write(myArray[y, x]);
            }
            Console.WriteLine();
        }
    }

    static bool A(int x, int y) { if (Input[y, x] == 1) return true; else return false; }
    static bool B(int x, int y) { try { if (Input[y - 1, x] == 1) return true; else return false; } catch { return false; } }
    static bool C(int x, int y) { try { if (Input[y, x - 1] == 1) return true; else return false; } catch { return false; } }
    static bool D(int x, int y) { try { if (Input[y, x + 1] == 1) return true; else return false; } catch { return false; } }
    static bool E(int x, int y) { try { if (Input[y + 1, x] == 1) return true; else return false; } catch { return false; } }

    static int[,] Input = { { 1,0,0,1,1,1,0,0 }, {1,0,0,0,0,1,0,0}, { 1,1,1,1,1,1,0,0  }, {1,0,0,0,0,0,1,1} , {1,0,1,0,0,0,1,0} };
    static int[,] OutputVH = new int[5, 8];
    static int[,] Solution = { { 1,0,0,1,0,1,0,0}, { 0,0,0,0,0,0,0,0}, { 1,0,0,0,0,1,0,0}, { 0,0,0,0,0,0,1,1} , {1,0,1,0,0,0,1,0} };
    static int xMax = 8;
    static int yMax = 5;

    static void Main(string[] args)
    {
        Console.WriteLine("Both Filterings");
        for (int y = 0; y < yMax; y++)
        {
            for (int x = 0; x < xMax; x++)
            {
                bool isZero = (!A(x, y) | ((B(x, y) & A(x, y) & E(x, y) & !C(x,y) & !D(x,y)) | (C(x, y) & A(x, y) & D(x, y) & !E(x,y) & !B(x,y)) | (A(x, y) & B(x, y) & C(x, y) & D(x, y) & E(x, y))));
                OutputVH[y, x] = (isZero ? 0 : 1); 
            }
        }
        PrintFunction(OutputVH, yMax, xMax);
        bool SolutionFound = true;
        for (int y = 0; y < yMax; y++)
            for (int x = 0; x < xMax; x++)
                if (OutputVH[y, x] != Solution[y, x]) SolutionFound = false;
        if (SolutionFound) Console.WriteLine("Found solution!");
    }
}

I'll leave it to you to simplify this further using boolean logic, if needed.

于 2011-08-05T13:51:55.537 回答