okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge branch 'f-1402-w' into f-140253623e56f

main
2.2 KiB78 linesraw
1{
2  "task": "Write a Python function `roman_to_int(s: str) -> int` that converts a Roman numeral (I, V, X, L, C, D, M, including subtractive forms like IV, IX, XL, XC, CD, CM) to an integer, and raises ValueError for an empty string or any character that is not a Roman numeral. Reply with one Python code block only.",
3  "reasoning_effort": "low",
4  "elapsed_s": 10.6,
5  "usage": {
6    "prompt_tokens": 121,
7    "completion_tokens": 1160,
8    "total_tokens": 1281,
9    "prompt_tokens_details": {
10      "cached_tokens": 0
11    }
12  },
13  "passed": 10,
14  "total": 10,
15  "results": [
16    {
17      "input": "III",
18      "expected": 3,
19      "got": 3,
20      "ok": true
21    },
22    {
23      "input": "IV",
24      "expected": 4,
25      "got": 4,
26      "ok": true
27    },
28    {
29      "input": "IX",
30      "expected": 9,
31      "got": 9,
32      "ok": true
33    },
34    {
35      "input": "LVIII",
36      "expected": 58,
37      "got": 58,
38      "ok": true
39    },
40    {
41      "input": "MCMXCIV",
42      "expected": 1994,
43      "got": 1994,
44      "ok": true
45    },
46    {
47      "input": "MMXXVI",
48      "expected": 2026,
49      "got": 2026,
50      "ok": true
51    },
52    {
53      "input": "CDXLIV",
54      "expected": 444,
55      "got": 444,
56      "ok": true
57    },
58    {
59      "input": "",
60      "expected": "ValueError",
61      "got": "ValueError",
62      "ok": true
63    },
64    {
65      "input": "ABC",
66      "expected": "ValueError",
67      "got": "ValueError",
68      "ok": true
69    },
70    {
71      "input": "MMX1",
72      "expected": "ValueError",
73      "got": "ValueError",
74      "ok": true
75    }
76  ],
77  "code": "def roman_to_int(s: str) -> int:\n    if not s:\n        raise ValueError(\"Empty string is not a valid Roman numeral\")\n\n    values = {\n        \"I\": 1,\n        \"V\": 5,\n        \"X\": 10,\n        \"L\": 50,\n        \"C\": 100,\n        \"D\": 500,\n        \"M\": 1000,\n    }\n\n    total = 0\n    i = 0\n\n    while i < len(s):\n        if s[i] not in values:\n            raise ValueError(f\"Invalid Roman numeral character: {s[i]}\")\n\n        if i + 1 < len(s) and s[i + 1] in values and values[s[i]] < values[s[i + 1]]:\n            total += values[s[i + 1]] - values[s[i]]\n            i += 2\n        else:\n            total += values[s[i]]\n            i += 1\n\n    return total\n"
78}