Re: Aufgaben und Übungen,

Image Screenshot_20240216_021725

 0 0 0 0 0    1
 1 0 0 0 1    1
 2 0 0 1 0    1
 3 0 0 1 1    0
 4 0 1 0 0    0
 5 0 1 0 1    1
 6 0 1 1 0    1
 7 0 1 1 1    1
 8 1 0 0 0    1
 9 1 0 0 1    0
10 1 0 1 0    1
11 1 0 1 1    1
12 1 1 0 0    0
13 1 1 0 1    0
14 1 1 1 0    1
15 1 1 1 1    0


 0 0 0 0 0    1
 1 0 0 0 1    1
 2 0 0 1 0    1
 5 0 1 0 1    1
 6 0 1 1 0    1
 7 0 1 1 1    1
 8 1 0 0 0    1
10 1 0 1 0    1
11 1 0 1 1    1
14 1 1 1 0    1


Gruppe 0:
 0 0 0 0 0    1
Gruppe 1:
 1 0 0 0 1    1
 2 0 0 1 0    1
 8 1 0 0 0    1
Gruppe 2:
 5 0 1 0 1    1
 6 0 1 1 0    1
10 1 0 1 0    1
Gruppe 3:
 7 0 1 1 1    1
11 1 0 1 1    1
14 1 1 1 0    1

0:1         0 0 0 -
0:2         0 0 - 0
0:8         - 0 0 0
1:5         0 - 0 1
2:6         0 - 1 0
2:10        - 0 1 0
8:10        1 0 - 0
5:7         0 1 - 1
6:7         0 1 1 -
6:14        - 1 1 0
10:11       1 0 1 -
10:14       1 - 1 0


0:1         0 0 0 -
10:11       1 0 1 -
6:7         0 1 1 -
0:2         0 0 - 0
8:10        1 0 - 0
5:7         0 1 - 1
1:5         0 - 0 1
2:6         0 - 1 0
10:14       1 - 1 0
0:8         - 0 0 0
2:10        - 0 1 0
6:14        - 1 1 0



Gruppe 0:
0:1         0 0 0 -
Gruppe 2:
10:11       1 0 1 -
6:7         0 1 1 -

Gruppe 0:
0:2         0 0 - 0
Gruppe 1:
8:10        1 0 - 0
Gruppe 2:
5:7         0 1 - 1

Gruppe 1:
1:5         0 - 0 1
2:6         0 - 1 0
Gruppe 2:
10:14       1 - 1 0

Gruppe 0:
0:8         - 0 0 0
Gruppe 1:
2:10        - 0 1 0
Gruppe 2:
6:14        - 1 1 0




0:1             0 0 0 -
10:11           1 0 1 -
6:7             0 1 1 -

Gruppe 0:
0:2         0 0 - 0
Gruppe 1:
8:10        1 0 - 0
Gruppe 2:
5:7         0 1 - 1

0:2:8:10        - 0 - 0
5:7             0 1 - 1

Gruppe 1:
1:5         0 - 0 1
2:6         0 - 1 0
Gruppe 2:
10:14       1 - 1 0

1:5:            0 - 0 1
2:6:10:14       - - 1 0

Gruppe 0:
0:8         - 0 0 0
Gruppe 1:
2:10        - 0 1 0
Gruppe 2:
6:14        - 1 1 0

0:8:2:10        - 0 - 0
2:10:6:14       - - 1 0


0:1             0 0 0 -
10:11           1 0 1 -
6:7             0 1 1 -
0:2:8:10        - 0 - 0
5:7             0 1 - 1
1:5:            0 - 0 1
2:6:10:14       - - 1 0
0:8:2:10        - 0 - 0
2:10:6:14       - - 1 0


0:1             0 0 0 -
10:11           1 0 1 -
6:7             0 1 1 -
0:2:8:10        - 0 - 0
0:8:2:10        - 0 - 0
5:7             0 1 - 1
1:5:            0 - 0 1
2:6:10:14       - - 1 0
2:10:6:14       - - 1 0


0:1             0 0 0 -
10:11           1 0 1 -
6:7             0 1 1 -
0:2:8:10        - 0 - 0
5:7             0 1 - 1
1:5:            0 - 0 1
2:10:6:14       - - 1 0

                    0   1   2   5   6   7   8   10  11  14
0:1                 *   *
10:11                                           *   *
6:7                                 *   *
0:2:8:10            *       *               *   *
5:7                             *       *
1:5:                    *       *
2:10:6:14                   *       *           *       *


                    0   1   2   5   6   7   8   10  11  14
10:11                                           *   *
0:2:8:10            *       *               *   *
5:7                             *       *
1:5:                    *       *
2:10:6:14                   *       *           *       *


10:11           1 0 1 -
0:2:8:10        - 0 - 0
5:7             0 1 - 1
1:5:            0 - 0 1
2:10:6:14       - - 1 0

    y <= (x3 and not x2 and x1) or
        (not x2 and not x0) or
        (not x3 and x2 and x0) or
        (not x3 and not x1 and x0) or
        (x1 and not x0);
    y <= not (
        (not x3 or x2 or not x1) and
        (x2 or x0) and
        (x3 or not x2 or not x0) and
        (x3 or x1 or not x0) and
        (not x1 or x0)
    );


library ieee;
use ieee.std_logic_1164.all;

entity quine20240216 is
port (
    x3, x2, x1, x0: in std_logic;
    y: out std_logic
);
end;

architecture behaviour of quine20240216 is
begin
    y <= (x3 and not x2 and x1) or
        (not x2 and not x0) or
        (not x3 and x2 and x0) or
        (not x3 and not x1 and x0) or
        (x1 and not x0);
end;

library ieee;
use ieee.std_logic_1164.all;

entity quine20240216testbench is
port (
    x3, x2, x1, x0: inout std_logic;
    y: out std_logic
);
end;

architecture behaviour of quine20240216testbench is
    component quine20240216
    port (
        x3, x2, x1, x0: in std_logic;
        y: out std_logic
    );
    end component;
begin
    q: quine20240216 PORT MAP (x3=>x3, x2=>x2, x1=>x1, x0=>x0, y=>y);

library ieee;
use ieee.std_logic_1164.all;

entity quine20240216 is
port (
    x3, x2, x1, x0: in std_logic;
    y: out std_logic
);
end;

architecture behaviour of quine20240216 is
begin
    y <= (x3 and not x2 and x1) or
        (not x2 and not x0) or
        (not x3 and x2 and x0) or
        (not x3 and not x1 and x0) or
        (x1 and not x0);
end;

library ieee;
use ieee.std_logic_1164.all;

entity quine20240216testbench is
port (
    x3, x2, x1, x0: inout std_logic;
    y: out std_logic
);
end;

architecture behaviour of quine20240216testbench is
    component quine20240216
    port (
        x3, x2, x1, x0: in std_logic;
        y: out std_logic
    );
    end component;
begin
    q: quine20240216 PORT MAP (x3=>x3, x2=>x2, x1=>x1, x0=>x0, y=>y);
    x0 <= '0' after 0 ns, '1' after 10 ns, '0' after 20 ns, '1' after 30 ns, '0' after 40 ns, '1' after 50 ns, '0' after 60 ns, '1' after 70 ns, '0' after 80 ns, '1' after 90 ns, '0' after 100 ns, '1' after 110 ns, '0' after 120 ns, '1' after 130 ns, '0' after 140 ns, '1' after 150 ns;

    x1 <= '0' after 0 ns, '0' after 10 ns, '1' after 20 ns, '1' after 30 ns, '0' after 40 ns, '0' after 50 ns, '1' after 60 ns, '1' after 70 ns, '0' after 80 ns, '0' after 90 ns, '1' after 100 ns, '1' after 110 ns, '0' after 120 ns, '0' after 130 ns, '1' after 140 ns, '1' after 150 ns;

    x2 <= '0' after 0 ns, '0' after 10 ns, '0' after 20 ns, '0' after 30 ns, '1' after 40 ns, '1' after 50 ns, '1' after 60 ns, '1' after 70 ns, '0' after 80 ns, '0' after 90 ns, '0' after 100 ns, '0' after 110 ns, '1' after 120 ns, '1' after 130 ns, '1' after 140 ns, '1' after 150 ns;

    x3 <= '0' after 0 ns, '0' after 10 ns, '0' after 20 ns, '0' after 30 ns, '0' after 40 ns, '0' after 50 ns, '0' after 60 ns, '0' after 70 ns, '1' after 80 ns, '1' after 90 ns, '1' after 100 ns, '1' after 110 ns, '1' after 120 ns, '1' after 130 ns, '1' after 140 ns, '1' after 150 ns;
end;

12.78125

12 / 2 =    6       Rest 0
6 / 2 =     3       Rest 0
3 / 2 =     1       Rest 1
1 / 2 =     0       Rest 1


0.78125
0.78125
-------
1.56250

1.56250
1.56250
---------
1.12500

0.78125 * 2 = 1.56250       1
0.56250 * 2 = 1.12500       1
0.125 * 2 = 0.25            0
0.25 * 2 = 0.5              0
0.5 * 2 = 1.0               1

1100,11001

1,10011001 * 2\^3

127 + 3 = 130

130 / 2 = 65                Rest 0
65 / 2 = 32                 Rest 1
32 / 2 = 16                 Rest 0
16 / 2 = 8                  Rest 0
8 / 2 = 4                   Rest 0
4 / 2 = 2                   Rest 0
2 / 2 = 1                   Rest 0
1 / 2 = 0                   Rest 1


0|10000010|10011001

0100.0001.0100.1100.1000.0000.0000b

0x414C800

So, ich fange jetzt an. Als erstes initialisiere ich die Zustände.

Ich mache es mit der Sortierung, wie vorher.

Entschuldigung, das hat etwas gedauert, weil ich habe auf der Strasse angefangen zu schreiben, dann bin ich zwischendrin nach hause und dann habe ich mich noch ausgeruht

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#define ERR_FILE_WRON_FORMAT            3
#define ERR_FILE_WRON_FORMAT_MSG        "IO-Error: File Wrong Format"
#define MAX_STR_INPUT_LEN               128


#define MAX_SPECIAL_STATES      3
#define MAX_STATES              128
#define MIN_STATE               1
#define SPECIAL_STATE_1         1
#define SPECIAL_STATE_2         2
#define SPECIAL_STATE_3         3
#define MAX_INPUTS              2
#define MAX_OUTPUTS             2
#define TRUE                    1
#define FALSE                   0
#define Z_A                     0
#define Z_B                     1


void readcsv (int a [], int b [], int y [MAX_OUTPUTS][MAX_STATES]) {
    int i;
    int j;
    int i1, i2;
    int x1, x2;
    char s [MAX_STR_INPUT_LEN];

    //scanf ("Zustand,Eingabe,Ausgabe,Folgezustandn");
    scanf ("%sn", s);
    if (strcmp (s, "Zustand,Eingabe,Ausgabe,Folgezustand") != 0) {
            printf ("%sn", ERR_FILE_WRON_FORMAT_MSG);
            exit (ERR_FILE_WRON_FORMAT);
    }


    for (i = 0;  i < MAX_STATES ;  i++) {
        scanf ("%i,%i,%i,%in", \&amp;i1, \&amp;x1, \&amp;y [Z_A][i], \&amp;a [i]);
        scanf ("%i,%i,%i,%in", \&amp;i2, \&amp;x2, \&amp;y [Z_B][i], \&amp;b [i]);

        if (x1 != Z_A) {
            printf ("%sn", ERR_FILE_WRON_FORMAT_MSG);
            exit (ERR_FILE_WRON_FORMAT);
        }
        if (x2 != Z_B) {
            printf ("%sn", ERR_FILE_WRON_FORMAT_MSG);
            exit (ERR_FILE_WRON_FORMAT);
        }
        if (i1 != (i+1)) {
            printf ("%sn", ERR_FILE_WRON_FORMAT_MSG);
            exit (ERR_FILE_WRON_FORMAT);
        }
        if (i2 != (i+1)) {
            printf ("%sn", ERR_FILE_WRON_FORMAT_MSG);
            exit (ERR_FILE_WRON_FORMAT);
        }
    }

return;
}

void printcsv (int a [], int b [], int y [MAX_OUTPUTS][MAX_STATES]) {
    int i;
    printf ("Zustand,Eingabe,Ausgabe,Folgezustandn");

    for (i = 0;  i < (MAX_STATES);  i++) {
        printf ("%i,%i,%i,%in", i+MIN_STATE, Z_A, y [Z_A][i], a [i]);
        printf ("%i,%i,%i,%in", i+MIN_STATE, Z_B, y [Z_B][i], b [i]);
    }

return;
}

void createnew (int a [], int b [], int y [MAX_OUTPUTS][MAX_STATES]) {
    time_t t;
    int i, j;
    int flag;
    int s;

    srand ((unsigned)time (\&amp;t));


    for (i = 0;  i < MAX_STATES;  i++) {
        a [i] = rand () % MAX_STATES;
        b [i] = rand () % MAX_STATES;
    }
    for (i = 0;  i < MAX_STATES;  i++) {
        y [Z_A][i] = rand () % MAX_OUTPUTS;
        y [Z_B][i] = rand () % MAX_OUTPUTS;
    }

return;
}

int deepsearch (int p [], int n, int a [], int b [], int m);
int deepsearch_inner (int p [], int i, int n, int a [], int b [], int j);

int deepsearch_inner (int p [], int i, int n, int a [], int b [], int j) {
    int r1 = 1;

    if (i >= n)
        return 1;

    if ((p [i] == a [j]) \&amp;\&amp; (p [i] != b [j])) {
        return deepsearch_inner (p, i+1, n, a, b, a[j]);
    }
    else if ((p [i] != a [j]) \&amp;\&amp; (p [i] == b [j])) {
        return deepsearch_inner (p, i+1, n, a, b, b[j]);
    }
    if ((p [i] == a [j]) \&amp;\&amp; (p [i] == b [j]))
        return (deepsearch_inner (p, i+1, n, a, b, a[j]) || deepsearch_inner (p, i+1, n, a, b, b[j]));
return 0;
}

int deepsearch (int p [], int n, int a [], int b [], int m) {
    int i;

    for (i = 0;  i < m;  i++)
        if (deepsearch_inner (p, 0, n, a, b, i))
            return 1;
return 0;
}

/*
void printtex (int a [], int b [], int y [MAX_OUTPUTS][MAX_STATES]) {
    int i, j;
    int codez = 8;
    printf("\documentclass{article}n");
    printf("\usepackage[utf8]{inputenc}n");
    printf("\usepackage{pgf, tikz}n");
    printf("\usetikzlibrary{arrows , automata , positioning}n");
    printf("\begin{document}nn");


    printf("\begin{center}n");
    printf("\begin{tikzpicture}[>=stealth',shorten >=1pt,auto,node distance=2.5cm]n");
    printf("%Knotenn");

    printf("\node (1) [state, thick] {1};n");
    printf("\node (2) [state, thick, right of= 1] {2};n");
    printf("\node (3) [state, thick, above of= 2, right of= 2] {3};n");
    printf("\node (4) [state, thick, above of= 3, right of= 1] {4};nn");

    printf("%Verbindungenn");
    printf("\path[thick,->]n");



    char *leftright [] = {"left", "right"};
    char *abovebelow [] = {"above", "below"};

    for (i = 0;  i < MAX_STATES;  i++) {
            if ((a [i] - MIN_STATE) == i)
                printf ("(%i) edge [loop] node {%i/%i} (%i)n", i + MIN_STATE, Z_A, y [Z_A][i], a [i]);
            else
                printf ("(%i) edge [bend angle=%i, bend %s,%s] node {%i/%i} (%i)n", i + MIN_STATE, (i+1)*10+(a[i]-MIN_STATE)*5, leftright [(i>(a [i]-MIN_STATE))\&amp;\&amp;((a [i]-MIN_STATE) != 3)], abovebelow    [((i+1)<=a[i])\&amp;\&amp;(a[i] != 4)], Z_A, y [Z_A][i], a [i]);
            if ((b [i] - MIN_STATE) == i)
                printf ("(%i) edge [loop] node {%i/%i} (%i)n", i + MIN_STATE, Z_B, y [Z_B][i], b [i]);
            else
                printf ("(%i) edge [bend angle=%i, bend %s,%s] node {%i/%i} (%i)n", i + MIN_STATE, (i+1)*25+(b[i]-MIN_STATE)*8, leftright [(i<=(b [i]-MIN_STATE)) \&amp;\&amp;((b [i]-MIN_STATE) != 3)], abovebelow [((i+MIN_STATE)>b [i])\&amp;\&amp;(b [i] != 4)], Z_B, y [Z_B][i], b [i]);
    }
    printf(";n");
    printf("\end{tikzpicture}n");
    printf("\end{center}n");

    printf ("\begin{center}n");
    printf ("\begin{tabular}{|l|l|l|l||l|l|l|l|}n");
    n");
    printf ("Zustand \&amp; Eingabe \&amp; Ausgabe \&amp; Folgezustand \&amp; \multicolumn{4}{|l|}{Codefolgezustand}n");
    n");
    printf BITTE IM PDF NACHGUCKEN
    n");
    for (i = 0;  i < MAX_STATES;  i++) {
        printf BITTE IM PDF NACHGUCKEN
        printf BITTE IM PDF NACHGUCKEN

    }
    n");
    printf ("\end{tabular}n");
    printf ("\end{center}n");


    printf ("\begin{center}n");
    printf ("\begin{verbatim}n");
    for (i = MIN_STATE;  i < (MAX_STATES + MIN_STATE);  i++) {
        printf ("z%i+ := ", i);
        for (j = 0;  j < MAX_STATES;  j++) {
            if ( a [j] == i )
                printf ("z%i and x or ", j+MIN_STATE, y [j]);
            if ( b [j] == i )
                printf ("z%i and not x or ", j+MIN_STATE, y [j]);
        }
        printf (" true;n");
    }
    printf ("end{verbatim}n");
    printf ("\end{center}n");

    printf("\end{document}n");

}*/

int main (int argc, char *argv []) {
    #define CREATE_NEW      0
    #define READ_CSV        1
    #define PRINT_TEX       0
    #define PRINT_CSV       1
    #define PRINT_NO_HELP   0
    #define PRINT_HELP      1

    char *existsstr [] = {"nicht gefundenn", "gefundenn"};

    int b [MAX_STATES];
    int a [MAX_STATES];
    int y [MAX_OUTPUTS][MAX_STATES];
    int argi;
    int createnew_readcsv = CREATE_NEW;
    int printraw_printtex_print_csv = PRINT_CSV;
    int printhelp = PRINT_NO_HELP;
    int p [4];

    for (argi = 1;  argi < argc;  argi++) {
        if ((strcmp ("--create-new", argv [argi]) == 0) || (strcmp ("-n", argv [argi]) == 0))
            createnew_readcsv = CREATE_NEW;
        if ((strcmp ("--read-csv", argv [argi]) == 0) || (strcmp ("-s", argv [argi]) == 0))
            createnew_readcsv = READ_CSV;
        if ((strcmp ("--print-csv", argv [argi]) == 0) || (strcmp ("-c", argv [argi]) == 0))
            printraw_printtex_print_csv = PRINT_CSV;
        //if ((strcmp ("--print-tex", argv [argi]) == 0) || (strcmp ("-t", argv [argi]) == 0))
        //        printraw_printtex_print_csv = PRINT_TEX;
        if ((strcmp ("--help", argv [argi]) == 0) || (strcmp ("-h", argv [argi]) == 0))
            printhelp = PRINT_HELP;
    }
    if (printhelp == PRINT_HELP) {
        printf ("--create-newn-nnn");
        printf ("--read-csvn-rnn");
        printf ("--print-csvn-cnn");
        printf ("--print-texn-tnn");
        printf ("--helpn-hnn");
        return 2;
    }
    if (createnew_readcsv == CREATE_NEW)
        createnew (a, b, y);
    else if (createnew_readcsv == READ_CSV)
        readcsv (a, b, y);
    //if (printraw_printtex_print_csv == PRINT_TEX)
    //    printtex (a, b, y);
   // else if (printraw_printtex_print_csv == PRINT_CSV)
        printcsv (a, b, y);
    int i;
    for (i = 0;  i < 4;  i++)
        p [i] = rand () % MAX_STATES;

    a [12] = 13;
    b [13] = 14;
    a [13] = 14;
    a [14] = 15;

    p [0] = 13;
    p [1] = 14;
    p [2] = 15;

    printf ("%s", existsstr[deepsearch (p, 3, a, b, MAX_STATES)]);

    a [12] = 13;
    b [13] = 22;
    a [13] = 22;
    a [22] = 15;

    p [0] = 13;
    p [1] = 22;
    p [2] = 15;

    printf ("%s", existsstr[deepsearch (p, 3, a, b, MAX_STATES)]);

return 0;
}

int deepsearch (int p [], int n, int a [], int b [], int m);
int deepsearch_inner (int p [], int i, int n, int a [], int b [], int j);

int deepsearch_inner (int p [], int i, int n, int a [], int b [], int j) {
    int r1 = 1;

    if (i >= n)
        return 1;

    if ((p [i] == a [j]) \&amp;\&amp; (p [i] != b [j])) {
        return deepsearch_inner (p, i+1, n, a, b, a[j]);
    }
    else if ((p [i] != a [j]) \&amp;\&amp; (p [i] == b [j])) {
        return deepsearch_inner (p, i+1, n, a, b, b[j]);
    }
    if ((p [i] == a [j]) \&amp;\&amp; (p [i] == b [j]))
        return (deepsearch_inner (p, i+1, n, a, b, a[j]) || deepsearch_inner (p, i+1, n, a, b, b[j]));
return 0;
}

int deepsearch (int p [], int n, int a [], int b [], int m) {
    int i;

    for (i = 0;  i < m;  i++)
        if (deepsearch_inner (p, 0, n, a, b, i))
            return 1;
return 0;
}