Category: Comparison

Question (EN): Jimin is better at games than Hoseok, and Hoseok is better at games than Youngsoo. While the three of them were playing the game, two more joined them. Of the two, Jinwoo is better than Hoseok but not as good as Jimin, and Donggyun is better than Jimin. Who is the worst gamer out of the five?
Question (KO): 지민이는 호석이보다 게임을 잘하고 호석이는 영수보다 게임을 잘합니다. 세 명이서 게임을 하는 도중 두 명이 더 참여하게 되었습니다. 두 명 중 진우는 호석이보다는 잘하지만 지민이보다는 못하고, 동균이는 지민이보다 잘합니다. 다섯 명 중 게임을 가장 못하는 사람은 누구인가요?

Answer: Youngsoo

Solution (Python):
var_a = 'Jimin'
var_b = 'Hoseok'
var_c = 'Youngsoo'
var_d = 'Jinwoo'
var_e = 'Donggyun'
list_a= []
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_f = 'Jimin'
var_g = 'Hoseok'
var_h = '>'
var_i = 'Hoseok'
var_j = 'Youngsoo'
var_k = '>'
var_l = 'Jinwoo'
var_m = 'Hoseok'
var_n = '>'
var_o = 'Jimin'
var_p = 'Jinwoo'
var_q = '>'
var_r = 'Donggyun'
var_s = 'Jimin'
var_t = '>'
list_b= []
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)
if "/" in str(var_m):
    var_m = eval(str(var_m))
list_b.append(var_m)
if "/" in str(var_l):
    var_l = eval(str(var_l))
list_b.append(var_l)
if "/" in str(var_k):
    var_k = eval(str(var_k))
list_b.append(var_k)
if "/" in str(var_j):
    var_j = eval(str(var_j))
list_b.append(var_j)
if "/" in str(var_i):
    var_i = eval(str(var_i))
list_b.append(var_i)
if "/" in str(var_h):
    var_h = eval(str(var_h))
list_b.append(var_h)
if "/" in str(var_g):
    var_g = eval(str(var_g))
list_b.append(var_g)
if "/" in str(var_f):
    var_f = eval(str(var_f))
list_b.append(var_f)
list_b.reverse()
global item_name_index_dict
items_name_list = list_a.copy()
conditions = []
condition_list = list_b.copy()
temp_stack = []
for index_, cond_ in enumerate(map(str, condition_list)):
    if cond_ in ("<", ">", "="):
        operand_right = temp_stack.pop()
        operand_left = temp_stack.pop()
        if cond_ == "=":
            cond_ = "=="
        conditions.append(f"{operand_left} {cond_} {operand_right}")
    else:
        if not cond_.isdigit():
            cond_ = "{" + cond_ + "}"
        temp_stack.append(cond_)
item_name_index_dict = {}
for perm in itertools.permutations(range(1, len(items_name_list) + 1)):
    item_name_index_dict = dict(zip(items_name_list, perm))
    formatted_conditions = \
        [condition.format_map(item_name_index_dict) for condition in conditions]
    if all(map(eval, formatted_conditions)):
        break
list_c = list(item_name_index_dict.keys())
list_c.sort(key=item_name_index_dict.get, reverse=True)
var_u = len(list_c)
var_v = list_c[var_u-1]
print(var_v)