File size: 1,931 Bytes
5154c4e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python3
from __future__ import annotations

from pathlib import Path

ABS_TOL = 1e-6
REL_TOL = 1e-4


def is_result_artifact(path: Path) -> bool:
    name = path.name.lower()
    return (
        any(k in name for k in ("summary", "result", "report", "diagnosis"))
        or path.suffix.lower() in {".txt", ".csv", ".xy", ".result"}
    )


def is_nonempty_file(path: Path) -> bool:
    if not is_result_artifact(path):
        return path.exists() and path.is_file()
    return path.exists() and path.is_file() and path.stat().st_size > 0


def read_text(path: Path) -> str:
    return path.read_text(encoding="utf-8", errors="ignore")


def parse_csv_values(path: Path) -> list[str]:
    content = read_text(path).strip()
    if not content:
        return []
    return [p.strip() for p in content.split(",")]


def close_enough(actual: float, target: float) -> bool:
    limit = max(ABS_TOL, REL_TOL * max(1.0, abs(target)))
    return abs(actual - target) <= limit


def check_task(root: Path) -> bool:
    required = ['mpc.inp', 'summary.txt']
    for rel in required:
        if not is_nonempty_file(root / rel):
            return False
    actual_parts = parse_csv_values(root / "summary.txt")
    expected_vals = [-15697500000.0, 0.000341892, 0.00034234]

    if len(actual_parts) != len(expected_vals):
        return False

    try:
        actual_vals = [float(v) for v in actual_parts]
    except (TypeError, ValueError):
        return False

    for a, g in zip(actual_vals, expected_vals):
        if not close_enough(a, g):
            return False

    return True


def evaluate() -> int:
    root = Path("/home/user/Desktop")
    try:
        ok = check_task(root)
    except Exception:
        ok = False
    return 1 if ok else 0


def main() -> int:
    result = evaluate()
    print("True" if result == 1 else "False")
    return 0


if __name__ == "__main__":
    raise SystemExit(main())