ENIGMA-0x01 (2023) - S0 (Mastermind - Annoula)

View as PDF

Submit solution

Points: 15 (partial)
Time limit: 1.0s
Memory limit: 16M

Authors:
Problem type
Allowed languages
Blockly, C, C++, Go, Haskell, Java, Pascal, Perl, PHP, Python

MASTERMIND - Annoula

Totos and Annoula, have finished their homework and decided to play the board game Mastermind. In Mastermind, one player hides a code of four different colors, and the other player tries to find it. In each round, the guessing player tries a combination of colors (that could be the repeating), and the one who hid the code provides feedback on the attempt. Specifically, they indicate how many colors from the secret code are present in the guessed combination and are in the correct position, and how many colors are present but in the wrong position. There are a total of 8 colors, and the goal of the second player is to find the code in the fewest attempts possible.

In our case, Annoula is the one hiding the code, and Totos is trying to find it. Help Annoula give the correct feedback to Totos by writing a program that calculates the number of correct colors that are also in the correct position, and the number of correct colors that are in the wrong position.

Input

The colors are 8 in total and are represented by one of the numbers 0-7. The format of the input is as follows:

1st line: 4 numbers A, B, C, D, representing the secret code set by Annoula.
2nd line: 1 number N, the number of Totos's attempts.
3rd to (N+2)th lines: 4 numbers x, y, z, w, representing Totos's attempt.

Output

1st to Nth line: For each attempt by Totοs, you will print 2 numbers, f and g, where f is the number of correct colors in the correct position, and g is the number of colors in the wrong position.

Note: It is not certain that Totis will ever find the secret code, and in the case that he finds it in some attempt before the Nth, he may continue trying other combinations for fun.

Examples

1st

STDIN

6 3 4 7
3
0 4 2 6
6 7 4 3
6 3 4 7

STDOUT

0 2
2 2
4 0

The game of the first example can be seen on the image.

2nd

STDIN

0 3 2 1
12
5 2 6 4
4 2 5 7
6 1 6 4
3 3 3 3
1 7 5 2
5 6 4 7
1 2 3 4
3 4 5 6
5 2 4 2
4 3 5 6
0 3 2 1
4 6 2 1

STDOUT

0 1
0 1
0 1
1 0
0 2
0 0
0 3
0 1
0 1
1 0
4 0
2 0

Comments

There are no comments at the moment.