Every failing sample below is the real generated Python, with the assertion or error that rejected it. Trial 0 runs at temperature 0, trials 1 and 2 at 0.7 — so a task passing 1/3 is a sampling-luck pass, not a reliable one. Models are ordered best first. Other technologies: C · Python · Bash · research · how to reproduce.
Setup and model serving are on the models index — including a script-free version using nothing but curl and a compiler; with a server running, this is the exact command that produced the samples below:
# Python suite (8 easy + 3 hard tasks, 3 trials each)
python scripts/eval_python.py --target <model> --set all --trials 3 \
--dump-failures results/failures
python scripts/eval_python.py --target <model> --set brutal --trials 3 \
--dump-failures results/failures --json > results/<model>-brutal-python.json
# each answer runs against hidden asserts in a subprocess with a timeout.
Served via llama.cpp CUDA · — tok/s · — GB RAM · coding total 117/126
No failures.
No failures.
Served via llama.cpp CUDA · — tok/s · — GB RAM · coding total 111/126
No failures.
No failures.
Served via llama.cpp CUDA · — tok/s · — GB RAM · coding total 108/126
No failures.
No failures.
Served via llama.cpp CUDA · — tok/s · — GB RAM · coding total 105/126
No failures.
No failures.
Served via llama.cpp CUDA · — tok/s · — GB RAM · coding total 105/126
No failures.
No failures.
Served via llama.cpp CUDA · — tok/s · — GB RAM · coding total 105/126
No failures.
No failures.
Served via llama.cpp CUDA · — tok/s · — GB RAM · coding total 105/126
No failures.
No failures.
Served via llama.cpp CUDA · — tok/s · — GB RAM · coding total 102/126
Implement in Python 3: `def is_valid_ipv4(s):` Returns True if s is a dotted-quad IPv4 address: four decimal octets 0-255, no leading zeros unless the octet is exactly '0'. Otherwise False. Reply with only a Python code block. No tests, no explanation.
(no code extracted)Implement in Python 3: `def json_diff(a, b):` Compares two JSON-like structures (dicts, lists, scalars). Returns a sorted list of dotted key paths where they differ: changed scalar/list values, keys present in only one side. Dicts are recursed into; lists and scalars are compared as whole values. Empty list means identical. Reply with only a Python code block. No tests, no explanation.
(no code extracted)(no code extracted)Served via llama.cpp CUDA · — tok/s · — GB RAM · coding total 102/126
No failures.
No failures.
Served via llama.cpp CUDA · — tok/s · — GB RAM · coding total 99/126
Implement in Python 3: `def csv_column_sum(path, col):` Reads the CSV file at path (first row is a header). Returns the sum of the numeric values in column col as a float. Reply with only a Python code block. No tests, no explanation.
import csv
def csv_column_sum(path, col):
total = 0.0
with open(path, 'r', newline='') as csvfile:
reader = csv.reader(csvfile)
next(reader) # Skip header row
for row in reader:
if col < len(row):
try:
total += float(row[col])
except ValueError:
pass # Skip non-numeric values
return totalimport csv
def csv_column_sum(path, col):
total = 0.0
with open(path, 'r', newline='') as csvfile:
reader = csv.reader(csvfile)
next(reader) # Skip header row
for row in reader:
if col < len(row):
try:
total += float(row[col])
except ValueError:
pass # Skip non-numeric values
return totalimport csv
def csv_column_sum(path, col):
total = 0.0
with open(path, 'r', newline='') as csvfile:
reader = csv.reader(csvfile)
next(reader) # Skip header row
for row in reader:
if col < len(row):
try:
total += float(row[col])
except ValueError:
pass # Skip non-numeric values
return totalImplement in Python 3: `def json_diff(a, b):` Compares two JSON-like structures (dicts, lists, scalars). Returns a sorted list of dotted key paths where they differ: changed scalar/list values, keys present in only one side. Dicts are recursed into; lists and scalars are compared as whole values. Empty list means identical. Reply with only a Python code block. No tests, no explanation.
def json_diff(a, b):
def _diff(path, x, y):
if type(x) != type(y):
return [path] if path else []
if isinstance(x, dict):
result = []
all_keys = set(x.keys()) | set(y.keys())
for key in all_keys:
new_path = f"{path}.{key}" if path else key
if key not in x:
result.append(new_path)
elif key not in y:
result.append(new_path)
else:
result.extend(_diff(new_path, x[key], y[key]))
return result
elif isinstance(x, list):
if len(x) != len(y):
return [path] if path else []
result = []
for i, (item_x, item_y) in enumerate(zip(x, y)):
new_path = f"{path}[{i}]" if path else f"[{i}]"
result.extend(_diff(new_path, item_x, item_y))
return result
else:
return [path] if path and x != y else []
return sorted(_diff("", a, b))def json_diff(a, b):
def _diff(path, x, y):
if type(x) != type(y):
return [path] if path else []
if isinstance(x, dict):
result = []
all_keys = set(x.keys()) | set(y.keys())
for key in all_keys:
new_path = f"{path}.{key}" if path else key
if key not in x:
result.append(new_path)
elif key not in y:
result.append(new_path)
else:
result.extend(_diff(new_path, x[key], y[key]))
return result
elif isinstance(x, list):
if len(x) != len(y):
return [path] if path else []
result = []
for i, (item_x, item_y) in enumerate(zip(x, y)):
new_path = f"{path}[{i}]" if path else f"[{i}]"
result.extend(_diff(new_path, item_x, item_y))
return result
else:
return [path] if path and x != y else []
return sorted(_diff("", a, b))def json_diff(a, b):
def _diff(path, x, y):
if type(x) != type(y):
return [path] if path else []
if isinstance(x, dict):
result = []
all_keys = set(x.keys()) | set(y.keys())
for key in all_keys:
new_path = f"{path}.{key}" if path else key
if key not in x:
result.append(new_path)
elif key not in y:
result.append(new_path)
else:
result.extend(_diff(new_path, x[key], y[key]))
return result
elif isinstance(x, list):
if len(x) != len(y):
return [path] if path else []
result = []
for i, (item_x, item_y) in enumerate(zip(x, y)):
new_path = f"{path}[{i}]" if path else f"[{i}]"
result.extend(_diff(new_path, item_x, item_y))
return result
else:
return [path] if path and x != y else []
return sorted(_diff("", a, b))Served via llama.cpp CUDA · — tok/s · — GB RAM · coding total 99/126
No failures.
No failures.
Served via llama.cpp CUDA · — tok/s · — GB RAM · coding total 96/126
No failures.
Implement in Python 3: `def json_diff(a, b):` Compares two JSON-like structures (dicts, lists, scalars). Returns a sorted list of dotted key paths where they differ: changed scalar/list values, keys present in only one side. Dicts are recursed into; lists and scalars are compared as whole values. Empty list means identical. Reply with only a Python code block. No tests, no explanation.
def json_diff(a, b):
def _diff(a, b, path):
diffs = []
if isinstance(a, dict) and isinstance(b, dict):
all_keys = sorted(set(a.keys()) | set(b.keys()))
for key in all_keys:
new_path = f"{path}.{key}" if path else key
if key not in a:
diffs.append(new_path)
elif key not in b:
diffs.append(new_path)
else:
diffs.extend(_diff(a[key], b[key], new_path))
elif isinstance(a, list) and isinstance(b, list):
if len(a) != len(b):
diffs.append(path)
else:
for i, (x, y) in enumerate(zip(a, b)):
new_path = f"{path}[{i}]"
diffs.extend(_diff(x, y, new_path))
else:
if a != b:
diffs.append(path)
return diffs
return sorted(_diff(a, b, ""))def json_diff(a, b):
def _diff(a, b, path):
diffs = []
if isinstance(a, dict) and isinstance(b, dict):
all_keys = sorted(set(a.keys()) | set(b.keys()))
for key in all_keys:
new_path = f"{path}.{key}" if path else key
if key not in a:
diffs.append(new_path)
elif key not in b:
diffs.append(new_path)
else:
diffs.extend(_diff(a[key], b[key], new_path))
elif isinstance(a, list) and isinstance(b, list):
if len(a) != len(b):
diffs.append(path)
else:
for i, (x, y) in enumerate(zip(a, b)):
new_path = f"{path}[{i}]"
diffs.extend(_diff(x, y, new_path))
else:
if a != b:
diffs.append(path)
return diffs
return sorted(_diff(a, b, ""))def json_diff(a, b):
def _diff(a, b, path):
diffs = []
if isinstance(a, dict) and isinstance(b, dict):
all_keys = sorted(set(a.keys()) | set(b.keys()))
for key in all_keys:
new_path = f"{path}.{key}" if path else key
if key not in a:
diffs.append(new_path)
elif key not in b:
diffs.append(new_path)
else:
diffs.extend(_diff(a[key], b[key], new_path))
elif isinstance(a, list) and isinstance(b, list):
if len(a) != len(b):
diffs.append(path)
else:
for i, (x, y) in enumerate(zip(a, b)):
new_path = f"{path}[{i}]"
diffs.extend(_diff(x, y, new_path))
else:
if a != b:
diffs.append(path)
return diffs
return sorted(_diff(a, b, ""))Served via llama.cpp CUDA · — tok/s · — GB RAM · coding total 96/126
Implement in Python 3: `def csv_column_sum(path, col):` Reads the CSV file at path (first row is a header). Returns the sum of the numeric values in column col as a float. Reply with only a Python code block. No tests, no explanation.
def csv_column_sum(path, col):
import csv
total = 0.0
with open(path, 'r', newline='') as f:
reader = csv.reader(f)
header = next(reader)
if col < 0 or col >= len(header):
raise IndexError("Column index out of range")
for row in reader:
if col < len(row):
try:
total += float(row[col])
except ValueError:
pass
return totaldef csv_column_sum(path, col):
import csv
total = 0.0
with open(path, 'r', newline='') as f:
reader = csv.reader(f)
header = next(reader)
if col < 0 or col >= len(header):
raise IndexError("Column index out of range")
for row in reader:
if col < len(row):
try:
total += float(row[col])
except ValueError:
pass
return totaldef csv_column_sum(path, col):
import csv
total = 0.0
with open(path, 'r', newline='') as f:
reader = csv.reader(f)
header = next(reader)
if col < 0 or col >= len(header):
raise IndexError("Column index out of range")
for row in reader:
if col < len(row):
try:
total += float(row[col])
except ValueError:
pass
return totalNo failures.
Served via llama.cpp CUDA · — tok/s · — GB RAM · coding total 94/126
No failures.
Implement in Python 3: `def topological_sort(deps):` deps maps each node (str) to a list of nodes it depends on. Returns a list of all nodes in an order where every node comes after its dependencies. Returns None if the graph has a cycle (including self-dependencies). Nodes mentioned only as dependencies are included. Reply with only a Python code block. No tests, no explanation.
def topological_sort(deps):
"""
Performs a topological sort on a directed graph defined by dependencies.
Args:
deps: A dictionary mapping a node (str) to a list of nodes it depends on.
Returns:
A list of nodes in topological order, or None if a cycle is detected.
"""
# Initialize in-degree count for all nodes
in_degree = {}
# Initialize adjacency list
graph = {}
# Collect all nodes
all_nodes = set(deps.keys())
for dependents in deps.values():
all_nodes.update(dependents)
# Initialize in-degree and adjacency list
for node in all_nodes:
in_degree[node] = 0
graph[node] = []
# Populate in-degree and adjacency list
for node, dependents in deps.items():
for dependent in dependents:
graph[node].append(dependent)
in_degree[dependent] += 1
# Initialize queue with nodes having no dependencies
queue = [node for node in all_nodes if in_degree[node] == 0]
result = []
while queue:
# Sort queue to ensure deterministic output (optional but good for testing)
queue.sort()
current = queue.pop(0)
result.append(current)
for neighbor in graph[current]:
in_degree[neighbor] -= 1
if in_degree[neighbor] == 0:
queue.append(neighbor)
# Check for cycle
if len(result) != len(all_nodes):
return None
return resultdef topological_sort(deps):
"""
Performs a topological sort on a directed graph defined by dependencies.
Args:
deps: A dictionary mapping a node (str) to a list of nodes it depends on.
Returns:
A list of nodes in topological order, or None if a cycle is detected.
"""
# Initialize in-degree count for all nodes
in_degree = {}
# Initialize adjacency list
graph = {}
# Collect all nodes
all_nodes = set(deps.keys())
for dependents in deps.values():
all_nodes.update(dependents)
# Initialize in-degree and adjacency list
for node in all_nodes:
in_degree[node] = 0
graph[node] = []
# Populate in-degree and adjacency list
for node, dependents in deps.items():
for dependent in dependents:
graph[node].append(dependent)
in_degree[dependent] += 1
# Initialize queue with nodes having no dependencies
queue = [node for node in all_nodes if in_degree[node] == 0]
result = []
while queue:
# Sort queue to ensure deterministic output (optional but good for testing)
queue.sort()
current = queue.pop(0)
result.append(current)
for neighbor in graph[current]:
in_degree[neighbor] -= 1
if in_degree[neighbor] == 0:
queue.append(neighbor)
# Check for cycle
if len(result) != len(all_nodes):
return None
return resultdef topological_sort(deps):
"""
Performs a topological sort on a directed graph defined by dependencies.
Args:
deps: A dictionary mapping a node (str) to a list of nodes it depends on.
Returns:
A list of nodes in topological order, or None if a cycle is detected.
"""
# Initialize in-degree count for all nodes
in_degree = {}
# Initialize adjacency list
graph = {}
# Collect all nodes
all_nodes = set(deps.keys())
for dependents in deps.values():
all_nodes.update(dependents)
# Initialize in-degree and adjacency list
for node in all_nodes:
in_degree[node] = 0
graph[node] = []
# Populate in-degree and adjacency list
for node, dependents in deps.items():
for dependent in dependents:
graph[node].append(dependent)
in_degree[dependent] += 1
# Initialize queue with nodes having no dependencies
queue = [node for node in all_nodes if in_degree[node] == 0]
result = []
while queue:
# Sort queue to ensure deterministic output (optional but good for testing)
queue.sort()
current = queue.pop(0)
result.append(current)
for neighbor in graph[current]:
in_degree[neighbor] -= 1
if in_degree[neighbor] == 0:
queue.append(neighbor)
# Check for cycle
if len(result) != len(all_nodes):
return None
return resultImplement in Python 3: `def json_diff(a, b):` Compares two JSON-like structures (dicts, lists, scalars). Returns a sorted list of dotted key paths where they differ: changed scalar/list values, keys present in only one side. Dicts are recursed into; lists and scalars are compared as whole values. Empty list means identical. Reply with only a Python code block. No tests, no explanation.
def json_diff(a, b):
def _diff(current_a, current_b, path):
changes = []
# Check if both are dicts
if isinstance(current_a, dict) and isinstance(current_b, dict):
# Keys present in both
all_keys = set(current_a.keys()) | set(current_b.keys())
for key in sorted(all_keys):
new_path = f"{path}.{key}" if path else key
if key in current_a and key in current_b:
changes.extend(_diff(current_a[key], current_b[key], new_path))
elif key in current_a:
changes.append(new_path)
else:
changes.append(new_path)
# Check if both are lists
elif isinstance(current_a, list) and isinstance(current_b, list):
# Compare lists by index
length = max(len(current_a), len(current_b))
for i in range(length):
new_path = f"{path}[{i}]"
if i < len(current_a) and i < len(current_b):
changes.extend(_diff(current_a[i], current_b[i], new_path))
elif i < len(current_a):
changes.append(new_path)
else:
changes.append(new_path)
# Scalars or mismatched types
else:
if current_a != current_b:
changes.append(path)
return changes
return sorted(_diff(a, b, ""))def json_diff(a, b):
def _diff(current_a, current_b, path):
changes = []
# Check if both are dicts
if isinstance(current_a, dict) and isinstance(current_b, dict):
# Keys present in both
all_keys = set(current_a.keys()) | set(current_b.keys())
for key in sorted(all_keys):
new_path = f"{path}.{key}" if path else key
if key in current_a and key in current_b:
changes.extend(_diff(current_a[key], current_b[key], new_path))
elif key in current_a:
changes.append(new_path)
else:
changes.append(new_path)
# Check if both are lists
elif isinstance(current_a, list) and isinstance(current_b, list):
length = max(len(current_a), len(current_b))
for i in range(length):
new_path = f"{path}[{i}]"
if i < len(current_a) and i < len(current_b):
changes.extend(_diff(current_a[i], current_b[i], new_path))
elif i < len(current_a):
changes.append(new_path)
else:
changes.append(new_path)
# Scalars (or mismatched types)
else:
if current_a != current_b:
changes.append(path)
return changes
return sorted(_diff(a, b, ""))def json_diff(a, b):
def _diff(current_a, current_b, path):
changes = []
# Check if both are dicts
if isinstance(current_a, dict) and isinstance(current_b, dict):
# Keys present in both
all_keys = set(current_a.keys()) | set(current_b.keys())
for key in sorted(all_keys):
new_path = f"{path}.{key}" if path else key
if key in current_a and key in current_b:
changes.extend(_diff(current_a[key], current_b[key], new_path))
elif key in current_a:
changes.append(new_path)
else:
changes.append(new_path)
# Check if both are lists
elif isinstance(current_a, list) and isinstance(current_b, list):
length = max(len(current_a), len(current_b))
for i in range(length):
new_path = f"{path}[{i}]"
if i < len(current_a) and i < len(current_b):
changes.extend(_diff(current_a[i], current_b[i], new_path))
elif i < len(current_a):
changes.append(new_path)
else:
changes.append(new_path)
# Scalars (or mismatched types)
else:
if current_a != current_b:
changes.append(path)
return changes
return sorted(_diff(a, b, ""))Served via llama.cpp CUDA · — tok/s · — GB RAM · coding total 93/126
No failures.
No failures.
Served via llama.cpp CUDA · — tok/s · — GB RAM · coding total 93/126
No failures.
No failures.
Served via llama.cpp CUDA · — tok/s · — GB RAM · coding total 93/126
No failures.
No failures.
Served via llama.cpp CUDA · — tok/s · — GB RAM · coding total 91/126
Implement in Python 3: `def csv_column_sum(path, col):` Reads the CSV file at path (first row is a header). Returns the sum of the numeric values in column col as a float. Reply with only a Python code block. No tests, no explanation.
import csv
def csv_column_sum(path, col):
with open(path, newline='') as f:
reader = csv.reader(f)
next(reader) # skip header
return sum(float(row[col]) for row in reader)import csv
def csv_column_sum(path, col):
with open(path, newline='') as f:
reader = csv.reader(f)
next(reader) # skip header
return sum(float(row[col]) for row in reader)import csv
def csv_column_sum(path, col):
with open(path, newline='') as f:
reader = csv.reader(f)
next(reader) # skip header
return sum(float(row[col]) for row in reader)Implement in Python 3: `def json_diff(a, b):` Compares two JSON-like structures (dicts, lists, scalars). Returns a sorted list of dotted key paths where they differ: changed scalar/list values, keys present in only one side. Dicts are recursed into; lists and scalars are compared as whole values. Empty list means identical. Reply with only a Python code block. No tests, no explanation.
def json_diff(a, b):
diffs = []
def compare(x, y, path):
if type(x) is not type(y):
diffs.append(path)
return
if isinstance(x, dict):
for k in x.keys() | y.keys():
if k not in x or k not in y:
diffs.append(path + "." + k)
else:
compare(x[k], y[k], path + "." + k)
elif isinstance(x, list):
if x != y:
diffs.append(path)
else:
if x != y:
diffs.append(path)
compare(a, b, "")
return sorted(diffs)def json_diff(a, b):
diffs = []
def compare(x, y, path):
if type(x) is not type(y):
diffs.append(path)
return
if isinstance(x, dict):
keys = set(x) | set(y)
for k in sorted(keys):
if k not in x or k not in y:
diffs.append(path + "." + k)
else:
compare(x[k], y[k], path + "." + k)
elif isinstance(x, list):
if x != y:
diffs.append(path)
else:
if x != y:
diffs.append(path)
compare(a, b, "")
return sorted(diffs)def json_diff(a, b):
diffs = []
def compare(x, y, path):
if type(x) is not type(y):
diffs.append(path)
return
if isinstance(x, dict):
keys = set(x) | set(y)
for k in sorted(keys):
if k not in x or k not in y:
diffs.append(path + "." + k)
else:
compare(x[k], y[k], path + "." + k)
elif isinstance(x, list):
if x != y:
diffs.append(path)
else:
if x != y:
diffs.append(path)
compare(a, b, "")
return sorted(diffs)Served via llama.cpp CUDA · — tok/s · — GB RAM · coding total 87/126
Implement in Python 3: `def is_valid_ipv4(s):` Returns True if s is a dotted-quad IPv4 address: four decimal octets 0-255, no leading zeros unless the octet is exactly '0'. Otherwise False. Reply with only a Python code block. No tests, no explanation.
import re
def is_valid_ipv4(s):
pattern = r'^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$'
if re.match(pattern, s):
return True
return Falseimport re
def is_valid_ipv4(s):
pattern = r'^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$'
if re.match(pattern, s):
return True
return FalseImplement in Python 3: `def topological_sort(deps):` deps maps each node (str) to a list of nodes it depends on. Returns a list of all nodes in an order where every node comes after its dependencies. Returns None if the graph has a cycle (including self-dependencies). Nodes mentioned only as dependencies are included. Reply with only a Python code block. No tests, no explanation.
def topological_sort(deps):
visited = set()
visiting = set()
sorted_nodes = []
def visit(node):
if node in visiting:
return False
if node in visited:
return True
visiting.add(node)
for dependency in deps.get(node, []):
if not visit(dependency):
return False
visiting.remove(node)
visited.add(node)
sorted_nodes.append(node)
return True
for node in list(deps.keys()) + [d for deps_list in deps.values() for d in deps_list]:
if node not in visited:
if not visit(node):
return None
return sorted_nodes[::-1]def topological_sort(deps):
visited = set()
visiting = set()
sorted_nodes = []
def visit(node):
if node in visiting:
return False
if node in visited:
return True
visiting.add(node)
for dependency in deps.get(node, []):
if not visit(dependency):
return False
visiting.remove(node)
visited.add(node)
sorted_nodes.append(node)
return True
for node in list(deps.keys()):
if not visit(node):
return None
return sorted_nodes[::-1]def topological_sort(deps):
visited = set()
visiting = set()
sorted_nodes = []
def visit(node):
if node in visiting:
return False
if node in visited:
return True
visiting.add(node)
for dependency in deps.get(node, []):
if not visit(dependency):
return False
visiting.remove(node)
visited.add(node)
sorted_nodes.append(node)
return True
for node in list(deps.keys()):
if not visit(node):
return None
return sorted_nodes[::-1]Implement in Python 3: `def json_diff(a, b):` Compares two JSON-like structures (dicts, lists, scalars). Returns a sorted list of dotted key paths where they differ: changed scalar/list values, keys present in only one side. Dicts are recursed into; lists and scalars are compared as whole values. Empty list means identical. Reply with only a Python code block. No tests, no explanation.
def json_diff(a, b, path=""):
diffs = []
if a == b:
return diffs
if isinstance(a, dict) and isinstance(b, dict):
all_keys = set(a.keys()) | set(b.keys())
for key in sorted(all_keys):
new_path = f"{path}.{key}" if path else key
if key not in a:
diffs.append(f"{new_path} (missing in a)")
elif key not in b:
diffs.append(f"{new_path} (missing in b)")
else:
diffs.extend(json_diff(a[key], b[key], new_path))
else:
diffs.append(path)
return diffsdef json_diff(a, b, path=""):
diffs = []
if a == b:
return diffs
if isinstance(a, dict) and isinstance(b, dict):
all_keys = set(a.keys()) | set(b.keys())
for key in sorted(all_keys):
new_path = f"{path}.{key}" if path else key
if key not in a:
diffs.append(f"{new_path} (missing in a)")
elif key not in b:
diffs.append(f"{new_path} (missing in b)")
else:
diffs.extend(json_diff(a[key], b[key], new_path))
else:
diffs.append(path)
return diffsdef json_diff(a, b, path=""):
diffs = []
if a == b:
return diffs
if isinstance(a, dict) and isinstance(b, dict):
all_keys = set(a.keys()) | set(b.keys())
for key in sorted(all_keys):
new_path = f"{path}.{key}" if path else key
if key not in a:
diffs.append(f"{new_path} (missing in a)")
elif key not in b:
diffs.append(f"{new_path} (missing in b)")
else:
diffs.extend(json_diff(a[key], b[key], new_path))
else:
diffs.append(path)
return diffsServed via llama.cpp CUDA · — tok/s · — GB RAM · coding total 82/126
No failures.
Implement in Python 3: `def topological_sort(deps):` deps maps each node (str) to a list of nodes it depends on. Returns a list of all nodes in an order where every node comes after its dependencies. Returns None if the graph has a cycle (including self-dependencies). Nodes mentioned only as dependencies are included. Reply with only a Python code block. No tests, no explanation.
```python
from collections import deque, defaultdict
def topological_sort(deps):
# Collect all unique nodes (keys and dependencies)
nodes = set(deps.keys())
for dep_list in deps.values():
nodes.update(dep_list)
nodes = list(nodes)
# Initialize adjacency list and in-degree dictionary
adj = defaultdict(list)
in_degree = {node: 0 for node in nodes}
# Build graph and in-degree counts
for node, dependencies in deps.items():
in_degree[node] = len(dependencies)
for dep in dependencies:
adj[dep].append(node)```python
from collections import deque, defaultdict
def topological_sort(deps):
# Collect all unique nodes (keys and dependencies)
nodes = set(deps.keys())
for dep_list in deps.values():
nodes.update(dep_list)
nodes = list(nodes)
# Initialize adjacency list and in-degree dictionary
adj = defaultdict(list)
in_degree = {node: 0 for node in nodes}
# Build graph and in-degree counts
for node, dependencies in deps.items():
in_degree[node] = len(dependencies)
for dep in dependencies:
adj[dep].append(node)Implement in Python 3: `def json_diff(a, b):` Compares two JSON-like structures (dicts, lists, scalars). Returns a sorted list of dotted key paths where they differ: changed scalar/list values, keys present in only one side. Dicts are recursed into; lists and scalars are compared as whole values. Empty list means identical. Reply with only a Python code block. No tests, no explanation.
(no code extracted)(no code extracted)(no code extracted)Served via llama.cpp CUDA · — tok/s · — GB RAM · coding total 61/126
Implement in Python 3: `def is_valid_ipv4(s):` Returns True if s is a dotted-quad IPv4 address: four decimal octets 0-255, no leading zeros unless the octet is exactly '0'. Otherwise False. Reply with only a Python code block. No tests, no explanation.
def is_valid_ipv4(s):
if s.count('.') != 3:
return False
for i in range(4):
octet = s[i * 3 : i * 3 + 3]
if not octet[0] == '0' and int(octet) > 255:
return False
if octet[0] == '0' and int(octet) != 0:
return False
return Truedef is_valid_ipv4(s):
if s.count('.') != 3:
return False
for i in range(4):
octet = s[i * 3 : i * 3 + 3]
if not octet[0] == '0' and int(octet) > 255:
return False
if octet[0] == '0' and int(octet) != 0:
return False
return Truedef is_valid_ipv4(s):
if s.count('.') != 3:
return False
for i in range(4):
octet = s[i * 3 : i * 3 + 3]
if not octet[0] == '0' and int(octet) > 255:
return False
if octet[0] == '0' and int(octet) != 0:
return False
return TrueImplement in Python 3: `def topological_sort(deps):` deps maps each node (str) to a list of nodes it depends on. Returns a list of all nodes in an order where every node comes after its dependencies. Returns None if the graph has a cycle (including self-dependencies). Nodes mentioned only as dependencies are included. Reply with only a Python code block. No tests, no explanation.
def topological_sort(deps):
# Create a set of all nodes
all_nodes = set(deps.keys())
# Create a set to keep track of visited nodes
visited = set()
# Create a list to store the topological order
order = []
def visit(node):
if node in visited:
return
visited.add(node)
for neighbour in deps.get(node, []):
visit(neighbour)
order.append(node)
# Visit all nodes
for node in all_nodes:
visit(node)
# If all nodes were visited, return the order
if len(order) == len(all_nodes):
return order
else:
return Nonedef topological_sort(deps):
# Create a set of all nodes
all_nodes = set(deps.keys())
# Create a set to keep track of visited nodes
visited = set()
# Create a list to store the topological order
order = []
def visit(node):
if node in visited:
return
visited.add(node)
for neighbour in deps.get(node, []):
visit(neighbour)
order.append(node)
# Visit all nodes
for node in all_nodes:
visit(node)
# If all nodes were visited, return the order
if len(order) == len(all_nodes):
return order
else:
return Nonedef topological_sort(deps):
# Create a set of all nodes
all_nodes = set(deps.keys())
# Create a set to keep track of visited nodes
visited = set()
# Create a list to store the topological order
order = []
def visit(node):
if node in visited:
return
visited.add(node)
for neighbour in deps.get(node, []):
visit(neighbour)
order.append(node)
# Visit all nodes
for node in all_nodes:
visit(node)
# If all nodes were visited, return the order
if len(order) == len(all_nodes):
return order
else:
return NoneImplement in Python 3: `def json_diff(a, b):` Compares two JSON-like structures (dicts, lists, scalars). Returns a sorted list of dotted key paths where they differ: changed scalar/list values, keys present in only one side. Dicts are recursed into; lists and scalars are compared as whole values. Empty list means identical. Reply with only a Python code block. No tests, no explanation.
def json_diff(a, b):
def diff_path(path, a, b):
if isinstance(a, dict) and isinstance(b, dict):
return [
f"{path}.{k}"
for k in set(a.keys()) ^ set(b.keys())
for subpath in diff_path(f"{path}.{k}", a[k], b.get(k, {}))
]
elif isinstance(a, list) and isinstance(b, list):
return [
f"{path}[{i}]"
for i, (av, bv) in enumerate(zip(a, b))
for subpath in diff_path(f"{path}[i]", av, bv)
]
else:
return [path] if a != b else []
return diff_path("", a, b)def json_diff(a, b):
def diff_path(path, a, b):
if isinstance(a, dict) and isinstance(b, dict):
return [
f"{path}.{k}"
for k in set(a.keys()) ^ set(b.keys())
for subpath in diff_path(f"{path}.{k}", a[k], b.get(k, {}))
]
elif isinstance(a, list) and isinstance(b, list):
return [
f"{path}[{i}]"
for i, (av, bv) in enumerate(zip(a, b))
for subpath in diff_path(f"{path}[i]", av, bv)
]
else:
return [path] if a != b else []
return diff_path("", a, b)def json_diff(a, b):
def diff_path(path, a, b):
if isinstance(a, dict) and isinstance(b, dict):
return [
f"{path}.{k}"
for k in set(a.keys()) ^ set(b.keys())
for subpath in diff_path(f"{path}.{k}", a[k], b.get(k, {}))
]
elif isinstance(a, list) and isinstance(b, list):
return [
f"{path}[{i}]"
for i, (av, bv) in enumerate(zip(a, b))
for subpath in diff_path(f"{path}[i]", av, bv)
]
else:
return [path] if a != b else []
return diff_path("", a, b)