import numpy as np
from scipy.optimize import linprog

# 능력치 순서: 힘, 생명, 지력, 정신, 행운, 속도
# 여기에 현재 능력 한계치 입력
current_stats = [
    228, 223, 303, 218, 308, 388
    ]

def optimize_levelups(current_stats):
    # 각 직업별 능력치 증가량 (행: 직업, 열: 스탯)
    stat_gains = np.array([
        [2, 1, 0, 0, 1, 0],  # 검술
        [0, 0, 1, 0, 1, 2],  # 인술
        [0, 1, 1, 2, 0, 0],  # 신술
        [0, 0, 2, 1, 0, 1],  # 마술
        [1, 0, 0, 0, 2, 1],  # 궁술
        [1, 2, 0, 1, 0, 0]   # 체술
    ])
    
    max_stat = 401 # 목표 능력 한계치
    required_stats = np.array([max_stat] * 6) - np.array(current_stats)
    
    # 선형 계획법 설정
    c = np.ones(6)  # 최소화할 목표 (레벨업 횟수)
    A_eq = stat_gains.T  # 능력치 증가 행렬의 전치
    b_eq = required_stats  # 목표 능력치 차이
    bounds = [(0, None)] * 6  # 각 직업의 레벨업 횟수는 0 이상
    
    # 선형 계획법 실행
    res = linprog(c, A_eq=A_eq, b_eq=b_eq, bounds=bounds, method='highs')
    
    if res.success:
        result = {"검술": round(res.x[0]), "인술": round(res.x[1]), "신술": round(res.x[2]), 
                  "마술": round(res.x[3]), "궁술": round(res.x[4]), "체술": round(res.x[5])}
        # 원하는 형식으로 출력
        for job, levelups in result.items():
            print(f"{job} : {levelups} 번")
    else:
        print("해결 불가능한 상태입니다.")


optimize_levelups(current_stats)

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: