Apply pre-commit fixes

This commit is contained in:
Aayam 2025-02-06 20:59:19 -08:00
parent f93c00a16b
commit e2ce20bcbb

View file

@ -1,6 +1,6 @@
import cmath import cmath
import random
import math import math
import random
from dataclasses import dataclass from dataclasses import dataclass
from typing import Optional, Tuple from typing import Optional, Tuple
@ -89,7 +89,7 @@ class ComplexArithmeticDataset(ProceduralDataset):
"result": (result.real, result.imag), "result": (result.real, result.imag),
}, },
} }
@staticmethod @staticmethod
def parse_string_to_complex(answer: str) -> complex: def parse_string_to_complex(answer: str) -> complex:
try: try:
@ -97,7 +97,7 @@ class ComplexArithmeticDataset(ProceduralDataset):
answer = answer.replace(" ", "").lower() answer = answer.replace(" ", "").lower()
# Convert mathematical notation 'i' to Python's 'j' for complex numbers # Convert mathematical notation 'i' to Python's 'j' for complex numbers
answer = answer.replace("i", "j") answer = answer.replace("i", "j")
# Handle real numbers (no imaginary part) # Handle real numbers (no imaginary part)
if "j" not in answer: if "j" not in answer:
student_result = complex(float(answer)) student_result = complex(float(answer))
@ -110,19 +110,19 @@ class ComplexArithmeticDataset(ProceduralDataset):
elif answer[-1] == "j" and not any(c in answer[:-1] for c in "+-"): elif answer[-1] == "j" and not any(c in answer[:-1] for c in "+-"):
# Convert "3j" to "3+1j" # Convert "3j" to "3+1j"
answer = answer.replace("j", "+1j") answer = answer.replace("j", "+1j")
# Ensure the string has an imaginary part, even if zero # Ensure the string has an imaginary part, even if zero
if "j" not in answer: if "j" not in answer:
answer += "+0j" answer += "+0j"
# Parse the normalized string into a complex number # Parse the normalized string into a complex number
student_result = complex(answer) student_result = complex(answer)
except ValueError: except ValueError:
return None return None
return student_result return student_result
def score_answer(self, answer: str, metadata: dict) -> float: def score_answer(self, answer: str, metadata: dict) -> float:
"""Score the answer using exponential distance-based scoring.""" """Score the answer using exponential distance-based scoring."""
if answer is None: if answer is None: