File size: 967 Bytes
31f0e47
8f447ab
 
 
c1cd746
31f0e47
8f447ab
31f0e47
 
 
 
 
 
c1cd746
31f0e47
 
 
8f447ab
31f0e47
 
8f447ab
31f0e47
 
 
8f447ab
31f0e47
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""task_medium.py - Four Quarter Growth grader."""

def grade(env) -> float:
    """
    Score based on 30% revenue growth over 4 quarters.
    Guaranteed strictly in (0.01, 0.99).
    """
    # 1. Survival & Budget Factor (0.01 to 0.6)
    if env.budget <= -50000:
        budget_score = 0.0
    elif env.budget <= 100000:
        # Bankrupt or lost money: Map (-50k, 100k) to (0.0, 0.3)
        budget_score = ((env.budget + 50000) / 150000) * 0.3
    else:
        # Map (100k, 130k+) to (0.3, 0.6)
        growth = (env.budget - 100000) / 30000 # 1.0 at 30% growth
        budget_score = 0.3 + min(0.3, growth * 0.3)

    # 2. Reputation Factor (0.0 to 0.3)
    rep_score = env.reputation * 0.3

    # 3. Persistence Factor (0.0 to 0.09)
    # Reward sticking it out for more quarters
    persistence = (len(env.history) / 4.0) * 0.09

    raw_score = 0.01 + budget_score + rep_score + persistence
    
    return round(float(min(0.99, max(0.01, raw_score))), 4)