# Echo server program
import socket

HOST = ''        # Symbolic name meaning all available interfaces
PORT = 50008              # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()

print('Connected by', addr)
while 1:
    data = conn.recv(1024)
    if not data: break
    numbers = data.split(" ")
    exactposcount = 0
    correctnumbercount = 0
    mynumbers = [2, 1, 1, 3]

    for i in range(0,4):
        if int(numbers[i]) == mynumbers[i]:
            exactposcount += 1
            mynumbers[i] = -1
            numbers[i] = '0'

    for i in range(0,4):
        if int(numbers[i]) in mynumbers:
            print('partial', numbers[i])
            correctnumbercount += 1
            mynumbers[mynumbers.index(int(numbers[i]))] = -1
                # mynumbers.index(z) is the first index containing z
            numbers[i] = '0'

    print("%d %d" % (exactposcount,correctnumbercount))
    print("~~~~~~~~")
    conn.send("%d %d" % (exactposcount,correctnumbercount))
onn.close()
