C Problems

The information below is specific to the C problems. General instructions / explanations can be found here.

The C implementations of the ECA systems come as a single C source file. For maximum compatibility with existing software model checking tools, the only data type which is used is int. Since input and outputs are expected as (one-letter) strings, the translation is realized by replacing letters by their position in the latin alphabet: "A" is replaced by 1, "X" by 24 and so on. At the top of each source file, the valid input symbols are explicitly listed along with their integer translations.

	// inputs
	int d = 4;
	int b = 2;
	int a = 1;
	int c = 3;
	int f = 6;
	int e = 5;

The ECA logic is contained in a method called calculate_output, which is a sequence of nested if-then-else blocks. The state of the ECA system is maintained in a set of attributes.

    int calculate_output(int input)
        if(input == 3                               // EVENT
            && (a7 != 0 && a0 == 9 && a6 == 0))	    // CONDITION		
            a3 = 4;                                 // ACTION
            a9 = 2;
            return 24;

At the bottom of this function, a sequence of if-statements checks whether the system is in an invalid state. If this is the case, an error is raised by a failed assertion. To identify the specific error in the source code, the assertion is labeled with the error ID.

    int calculate_output(int input) {
        if((a23 == 0 && a3 != 0 && a26 == 3))
error23:        assert(0);

The main() function, which is also contained in the source file, consists of the main loop which connects the ECA system to inputs (via stdin) and outputs (via stdout).

int main()
    // default output
    int output = -1;

    // main i/o-loop
        // read input
        int input;
        scanf("%d", &input);        

        // operate eca engine
        output = calculate_output(input);

        if(output == -2)
            fprintf(stderr, "Invalid input: %d\n", input);
        else if(output != -1)
            printf("%d\n", output);

The systems can be compiled using gcc and executed without any prerequisites.

    $ gcc -o ProblemX ProblemX.c 
    $ ./ProblemX