from pwn import *
import time

def sin(exp): return math.sin(math.radians(eval(str(exp))))
def cos(exp): return math.cos(math.radians(eval(str(exp))))
def sqrt(exp): return math.sqrt(eval(str(exp)))

def solve(expression):
    newexpr = ''
    for i, c in enumerate(expression):
        if c == '|' and expression[i-5:].startswith('sqrt'):
            newexpr += "abs("
        elif c == '|':
            newexpr += ')'
        else:
            newexpr += c
    
    #print(newexpr)
    return str(eval(newexpr))

conn = remote('localhost', 3005)
#conn = process(['python3', './friend-generator.py'])

time.sleep(0.1)
print(conn.recv())
conn.send('yes\n'.encode())
time.sleep(0.1)

names = []

while True:
    data = conn.recv().decode()
    try:
        name = data[data.index('name'):].split('\n')[0][8:].split(',')[0]
        expression = data[data.index('first: '):].split('\n')[1]
    except ValueError:
        print(data)
        exit(0)
    solution = solve(expression)
    #print(f"= {solution}")
    print(name)
    names.append(name)
    conn.send((solution + "\n").encode())
    time.sleep(0.1)
