"""Solution for scan_practice.py."""
import re

PRICE = (0.20, 1.25)  # gpt-5.4-nano, USD per 1M tokens (input, output): the lab's list prices


def found(ranks: list, k: int) -> int:
    return sum(r <= k for r in ranks)


def is_right(answer: str, correct: float) -> bool:
    nums = re.findall(r"\d+(?:\.\d+)?", answer.replace(",", ""))
    return any(abs(float(n) - correct) < 0.005 for n in nums)


def names_on(card: str, kind: str) -> list:
    if kind == "memo":
        return re.findall(r"Project (\w+)", card)
    if kind == "dashboard":
        return re.findall(r"(\w+)-service", card)
    lines = card.strip().splitlines()
    return [lines[0].strip()] if lines else []


def unknown_names(card: str, kind: str, known: list) -> list:
    names = names_on(card, kind)
    if not names:
        return ["(no name)"]
    out = []
    for n in names:
        if n not in known and n not in out:
            out.append(n)
    return out


def cost_per_1000(input_tokens: int, output_tokens: int, calls: int, price=PRICE) -> float:
    dollars = (input_tokens * price[0] + output_tokens * price[1]) / 1e6
    return dollars / calls * 1000
