Tier 1 — floor
5/5
seed 1 (passed): all cases passed
115 tokens · 2.688s
extracted code
def is_palindrome(s):
"""
Returns True if the input string is a palindrome, ignoring case, spaces, and punctuation.
Parameters:
s (str): The input string to check.
Returns:
bool: True if the string is a palindrome, False otherwise.
"""
cleaned_s = ''.join((e for e in s if e.isalnum())).lower()
return cleaned_s == cleaned_s[::-1]
Tier 2 — edge-case handling
5/5
seed 1 (passed): all cases passed
202 tokens · 0.931s
extracted code
def second_largest_unique(nums):
"""
Returns the second largest unique value in a list of integers.
Args:
nums (list): A list of integers.
Returns:
int: The second largest unique value if it exists, otherwise None.
"""
if not isinstance(nums, list):
raise ValueError('Input must be a list')
if not all((isinstance(num, int) for num in nums)):
raise ValueError('List must contain only integers')
unique_nums = set(nums)
if len(unique_nums) < 2:
return None
sorted_unique_nums = sorted(unique_nums, reverse=True)
return sorted_unique_nums[1]
Tier 3 — multi-class interface
0/5
seed 1 (FAILED): return_book(111) should return True
863 tokens · 3.525s
extracted code
class Book:
def __init__(self, title, author, isbn):
"""
Initialize a new Book object.
Args:
title (str): The title of the book.
author (str): The author of the book.
isbn (str): The ISBN number of the book.
"""
self.title = title
self.author = author
self.isbn = isbn
self.available = True
def __repr__(self):
return f"Book('{self.title}', '{self.author}', '{self.isbn}')"
class Library:
def __init__(self):
"""
Initialize a new Library object.
"""
self.books = []
def add_book(self, book):
"""
Add a new Book to the library.
Args:
book (Book): The Book object to be added.
"""
if not isinstance(book, Book):
raise ValueError('Invalid book object')
self.books.append(book)
def checkout_book(self, isbn):
"""
Check out a book by its ISBN number.
Args:
isbn (str): The ISBN number of the book to be checked out.
Returns:
bool: True if the book is available and checked out successfully, False otherwise.
... [truncated, 1270 more chars]
Tier 4 — bug-fix
5/5
seed 1 (passed): all cases passed
307 tokens · 1.339s
extracted code
def apply_discount(price, discount_percent):
"""
Applies a percentage discount to a price.
Args:
price (float): The original price.
discount_percent (int or float): A percentage value between 0 and 100.
Returns:
float: The discounted price, rounded to 2 decimal places.
Raises:
ValueError: If the discount percent is negative or greater than 100.
ValueError: If the price is negative.
Example:
>>> apply_discount(100.0, 20)
80.0
"""
if not isinstance(discount_percent, (int, float)) or discount_percent < 0 or discount_percent > 100:
raise ValueError('Discount percent must be a number between 0 and 100')
if price < 0:
raise ValueError('Price cannot be negative')
discount = price * (discount_percent / 100)
new_price = price - discount
return round(new_price, 2)
Tier 5 — schema cross-reference
0/5
seed 1 (FAILED): exception: 'name'
618 tokens · 2.548s
extracted code
def top_customers(orders, customers, n):
"""
Returns the top n customers by total order amount.
Args:
orders (list of dicts): List of orders with keys 'order_id', 'customer_id', and 'amount'.
customers (list of dicts): List of customers with keys 'customer_id' and 'name'.
n (int): Number of top customers to return.
Returns:
list of dicts: List of top n customers sorted by total order amount in descending order.
"""
customer_data = {}
for order in orders:
customer_id = order['customer_id']
if customer_id not in customer_data:
customer_data[customer_id] = {'total_spent': 0, 'order_count': 0}
customer_data[customer_id]['total_spent'] += order['amount']
customer_data[customer_id]['order_count'] += 1
sorted_customers = sorted(customer_data.items(), key=lambda x: x[1]['total_spent'], reverse=True)
result = [{'name': customer[1]['name'], 'total_spent': customer[1]['total_spent'], 'order_count': customer[1]['order_count']} for customer in sorted_customers[:n]]
return result
orders = [{'order_id': 1, 'customer_id': 1, 'amount': 10}, {'order_id': 2, 'customer_id': 1, 'amount'
... [truncated, 247 more chars]
Tier 6 — strict JSON format
0/5
seed 1 (FAILED): low_stock_items = {'Widget'}, expected {'Widget', 'Gizmo'}
29 tokens · 0.273s
raw response
{"low_stock_items": ["Widget"], "total_value": 59.38, "most_expensive_item": "Gizmo"}