Category: Correspondence

Question (EN): There are three digit numbers where the tens digit is 3 and the sum of the ones digit and the hundreds digit is 5. Each digit in this three-digit number is different, and when you add 124 to this number, all digits are equal. Find a three digit number.
Question (KO): 십의 자리 숫자는 3이고, 일의 자리 수와 백의 자리 수의 합은 5인 세 자리 수가 있습니다. 이 세 자리 수의 각 자리 숫자는 모두 다르고, 이 수에 124를 더하면 각 자리 숫자가 모두 같아집니다. 세 자리 수를 구하시오.

Answer: 431

Solution (Python):
var_a = 'A'
var_b = 3
var_c = 'B'
var_d = '+'
var_e = 124
var_f = '='
var_g = 'C'
var_h = 'C'
var_i = 'C'
list_a= []
if "/" in str(var_i):
    var_i = eval(str(var_i))
list_a.append(var_i)
if "/" in str(var_h):
    var_h = eval(str(var_h))
list_a.append(var_h)
if "/" in str(var_g):
    var_g = eval(str(var_g))
list_a.append(var_g)
if "/" in str(var_f):
    var_f = eval(str(var_f))
list_a.append(var_f)
if "/" in str(var_e):
    var_e = eval(str(var_e))
list_a.append(var_e)
if "/" in str(var_d):
    var_d = eval(str(var_d))
list_a.append(var_d)
if "/" in str(var_c):
    var_c = eval(str(var_c))
list_a.append(var_c)
if "/" in str(var_b):
    var_b = eval(str(var_b))
list_a.append(var_b)
if "/" in str(var_a):
    var_a = eval(str(var_a))
list_a.append(var_a)
list_a.reverse()
var_j=""
for i in list_a:
    i = str(i)
    var_j = var_j + i
var_k = 'A'
ans_dict = dict()
var_j = var_j.replace('×','*')
var_j = var_j.replace('x','*')
var_j = var_j.replace('÷','/')
variable_candi = set(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'])
for v in set(var_j):
    if v in variable_candi:
        ans_dict[v] = 1
candi = list(itertools.product('0123456789', repeat=len(ans_dict)))
for c in candi:
    temp = var_j
    for i, (k, _) in enumerate(ans_dict.items()):
        temp = temp.replace(k, str(c[i]))
    term_list = []
    op_list = []
    temp_c = ''
    for tc in temp:
        if tc not in '+-*/=><().':
            temp_c += tc
        else:
            op_list.append(tc)
            term_list.append(temp_c)
            temp_c = ''
    term_list.append(temp_c)
    new_eq = ''
    for i in range(len(op_list)):
        new_eq += str(int(term_list[i]))+op_list[i]
    new_eq += str(int(term_list[-1]))
    if len(new_eq) == len(var_j):
        new_eq=new_eq.replace('=', '==')
        new_eq=new_eq.replace('>==', '>=')
        new_eq=new_eq.replace('<==', '<=')
        eval_result = False
        try:
            eval_result = eval(new_eq)
        except:
            pass
        if eval_result:
            for i, (k, _) in enumerate(ans_dict.items()):
                ans_dict[k] = int(c[i])
var_l = ans_dict[var_k]
var_m = 3
var_n = 'A'
var_o = 3
var_p = 'B'
var_q = '+'
var_r = 124
var_s = '='
var_t = 'C'
var_u = 'C'
var_v = 'C'
list_b= []
if "/" in str(var_v):
    var_v = eval(str(var_v))
list_b.append(var_v)
if "/" in str(var_u):
    var_u = eval(str(var_u))
list_b.append(var_u)
if "/" in str(var_t):
    var_t = eval(str(var_t))
list_b.append(var_t)
if "/" in str(var_s):
    var_s = eval(str(var_s))
list_b.append(var_s)
if "/" in str(var_r):
    var_r = eval(str(var_r))
list_b.append(var_r)
if "/" in str(var_q):
    var_q = eval(str(var_q))
list_b.append(var_q)
if "/" in str(var_p):
    var_p = eval(str(var_p))
list_b.append(var_p)
if "/" in str(var_o):
    var_o = eval(str(var_o))
list_b.append(var_o)
if "/" in str(var_n):
    var_n = eval(str(var_n))
list_b.append(var_n)
list_b.reverse()
var_w=""
for i in list_b:
    i = str(i)
    var_w = var_w + i
var_x = 'B'
ans_dict = dict()
var_w = var_w.replace('×','*')
var_w = var_w.replace('x','*')
var_w = var_w.replace('÷','/')
variable_candi = set(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'])
for v in set(var_w):
    if v in variable_candi:
        ans_dict[v] = 1
candi = list(itertools.product('0123456789', repeat=len(ans_dict)))
for c in candi:
    temp = var_w
    for i, (k, _) in enumerate(ans_dict.items()):
        temp = temp.replace(k, str(c[i]))
    term_list = []
    op_list = []
    temp_c = ''
    for tc in temp:
        if tc not in '+-*/=><().':
            temp_c += tc
        else:
            op_list.append(tc)
            term_list.append(temp_c)
            temp_c = ''
    term_list.append(temp_c)
    new_eq = ''
    for i in range(len(op_list)):
        new_eq += str(int(term_list[i]))+op_list[i]
    new_eq += str(int(term_list[-1]))
    if len(new_eq) == len(var_w):
        new_eq=new_eq.replace('=', '==')
        new_eq=new_eq.replace('>==', '>=')
        new_eq=new_eq.replace('<==', '<=')
        eval_result = False
        try:
            eval_result = eval(new_eq)
        except:
            pass
        if eval_result:
            for i, (k, _) in enumerate(ans_dict.items()):
                ans_dict[k] = int(c[i])
var_y = ans_dict[var_x]
list_c= []
if "/" in str(var_y):
    var_y = eval(str(var_y))
list_c.append(var_y)
if "/" in str(var_m):
    var_m = eval(str(var_m))
list_c.append(var_m)
if "/" in str(var_l):
    var_l = eval(str(var_l))
list_c.append(var_l)
list_c.reverse()
var_z=""
for i in list_c:
    i = str(i)
    var_z = var_z + i
print(int(var_z))