ENIGMA-0x01 (2023) - S3 (Mastermind - Totos) **

View as PDF

Submit solution

Points: 40 (partial)
Time limit: 3.0s
Memory limit: 256M

Authors:
Problem type
Allowed languages
Blockly, C, C++, Haskell, Java, Pascal, Perl, Python
MASTERMIND - Totos

Totos and Annoula, have finished their homework and decided to play the board game Mastermind. In Mastermind, one player hides a password 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 password provides feedback on the attempt. Specifically, they indicate how many colors from the secret password 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 password in the fewest attempts possible.

In our case, Annoula is the one hiding the password, and Totos is trying to find it. Sometimes Annoula wants to help Totos by revealing some colors from the password. The task is to help Totos find the secret password in the fewest attempts possible by writing a program that interacts with the computer.

Input - Interraction System

1st line: a single number N, the number of passwords in the testcase.
Next lines:Initially, on a line, there are 4 characters (a, b, c, d), each of which is either a number from 0 to 7 or the character '?', representing Annoula's hint. After each attempt, there are 2 numbers - Annoula's feedback for the attempt. If the feedback is the numbers 4 and 0, the next password is provided.

Your goal is to find the N passwords, specifically the numbers hidden behind the question marks '?' in each password.
The problem is interactive. After reading the 4 characters, the program starts by printing 4 numbers (x, y, z, w) as Totos's first attempt. Then the grader provides feedback for the attempt (the grader simulates Annoula), indicating the number of correct colors in the correct position and the number of correct colors in the wrong position. The program uses this information to decide on the next combination, and the process repeats until the hidden password is found (i.e., the grader's response is 4 0). Subsequently, the program reads Annoula's hint for the next password, and so on.

Grading

The scoring in this problem will depend on the number of attempts made by the program. Specifically, the grader will find the password where the program made the most attempts, and according to the following table, the corresponding percentage of points will be given.

Max Attempts Percentage(%)
<=17 100
<=32 80
<=79 50
<=94 40
<=326 30
<=1680 20
<=4096 10
>4096 0

Examples

1st
STDIN STDOUT
1
? ? ? ?
0 4 2 6
0 2
6 7 4 3
2 2
6 3 4 7
4 0
2nd
STDIN STDOUT
2
0 1 2 ?
0 1 2 3
4 0
4 ? ? 7
4 5 0 7
3 0
4 5 1 7
4 0

Subtasks

Testcase Description
1 In Annoula's hints there will be only 1 question mark '?'. This means that only 1 color needs to be found.
2 In Annoula's hints there will be up to 2 question marks '?'.
3 In Annoula's hints there will be up to 3 question marks '?'.
4 In Annoula's hints there will be up to 4 question marks '?'.

Cheat code ;)

C
#include<stdio.h>

void solve(){
    char a,b,c,d;
    scanf("%c %c %c %c", &a, &b, &c, &d);
    getchar();
    while(1){
        printf("0 0 0 0\n");
        int cc, cw;
        scanf("%d %d", &cc, &cw);
        getchar();
        if(cc==4) return;
    }
}

int main(){
    int n;
    scanf("%d", &n);
    getchar();
    for(int i=0; i<n; i++){
        solve();
    }
    return 0;
}
C++
#include<iostream>

using namespace std;

void solve(){
    char a,b,c,d;
    cin>>a>>b>>c>>d;
    while(1){
        cout<<"0 0 0 0"<<endl;
        int cc,cw;
        cin>>cc>>cw;
        if(cc==4)return;
    }
}

int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        solve();
    }
}
Python
def solve():
  code=input()
  code_split=code.split(' ')
  a,b,c,d=code_split[0],code_split[1],code_split[2],code_split[3]
  while 1:
    print('0 0 0 0')
    feedback=input()
    if feedback.split(' ')[0]=='4':
      return

n=input()
n=int(n)
for i in range(n):
  solve()

Comments

There are no comments at the moment.