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 Vulkan · 27.8 tok/s · 28.8 GB RAM · coding total 115/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.
```python
def json_diff(a, b):
"""
Compares two JSON-like structures and returns a sorted list of dotted key paths
where they differ.
Args:
a: First JSON-like structure (dict, list, or scalar)
b: Second JSON-like structure (dict, list, or scalar)
Returns:
Sorted list of dotted key paths where differences exist.
Empty list means identical.
"""
def _diff(a, b, path):
"""
Recursively compare two values and yield paths where they differ.
"""
# If both are dicts
if isinstance(a, dict) and isinstance(b, dict):
all_keys = set(a.keys()) | set(b.keys())
for key in all_keys:
new_path = path + [str(key)] if path else [str(key)]
if key not in a:
# Key only in b
yield '.'.join(new_path)
elif key not in b:
# Key only in a
yield '.'.join(new_path)
else:
# Both have the key, recurse
yield from _diff(a[key], b[key], new_path)
# If both are lists
elif isinstance(a, list) and isinstance(b, list):
if a != b:
yield '.'.join(path) if path else ''
# If types differ or one is not dict/list (scalar comparison)
else:
if a != b:
yield '.'.join(path) if path else ''
# Start with empty path
paths = list(_diff(a, b, []))
# Filter out empty strings if any (shouldn't happen with proper handling)
# Actually, if path is empty and they differ at root, we need to handle that.
# Let's reconsider: if path is empty and they differ, what path do we report?
# The problem says "dotted key paths". For root-level differences, perhaps we report '' or handle differently.
# Looking at the spec: "keys present in only one side" - these are dict keys.
# "changed scalar/list values" - these are values at some path.
# If the root itself is different (e.g., a=1, b=2), what's the path?
# Let me re-read: "Returns a sorted list of dotted key paths where they differ"
# For root-level scalar difference, there's no key path. But the spec says empty list means identical.
# So if a=1, b=2, they differ, so we need to report something.
# Perhaps we report an empty string or handle root differently.
# Let me reconsider the approach. The paths should be relative to the root.
# If root values differ and are scalars/lists, we might report '' or handle it.
# But typically in such diff functions, root-level differences might not have a path.
# Let me check: if a and b are both dicts, we iterate keys. If they're scalars/lists at root,
# and they differ, we need to report that difference somehow.
# Actually, looking more carefully: the function compares structures. If the entire structures
# are different scalars/lists, we should report that. But what path?
# Perhaps we should not yield empty paths. Let me think about what makes sense.
# If a = {"x": 1} and b = {"x": 2}, path is "x"
# If a = {"x": 1} and b = {"y": 1}, paths are "x" and "y"
# If a = [1, 2] and b = [1, 3], they differ as whole lists. What path?
# The spec says "lists and scalars are compared as whole values". So if the root is a list
# and it differs, we need to report it. But there's no key path for the root.
# I think for root-level differences where there's no key, we might report an empty string
# or perhaps the convention is different. Let me look at the requirement again:
# "Empty list means identical." So if they differ, we return non-empty.
# Let me adjust: if path is empty and values differ, we yield '' (empty string).
# But that might be odd. Alternatively, maybe we don't need to handle root-level
# scalar/list differences specially if the caller always passes dicts.
# Let me just implement it straightforwardly and see.Served via llama.cpp Vulkan · 51.4 tok/s · 0.3 GB RAM · coding total 109/126
No failures.
No failures.
Served via llama.cpp Vulkan · 33.6 tok/s · 0.3 GB RAM · coding total 107/126
No failures.
No failures.
Served via llama.cpp Vulkan · 47.1 tok/s · 0.5 GB RAM · coding total 105/126
No failures.
No failures.
Served via llama.cpp Vulkan · 55.5 tok/s · 1.4 GB RAM · coding total 105/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='', encoding='utf-8') 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, TypeError):
pass # Skip non-numeric values
return totalimport csv
def csv_column_sum(path, col):
total = 0.0
with open(path, 'r', newline='', encoding='utf-8') 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, TypeError):
pass # Skip non-numeric values
return totalimport csv
def csv_column_sum(path, col):
total = 0.0
with open(path, 'r', newline='', encoding='utf-8') 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, TypeError):
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 types differ, they're different at this path
if type(x) != type(y):
return [path] if path else []
# Handle dicts
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
# Handle lists
if isinstance(x, list):
result = []
max_len = max(len(x), len(y))
for i in range(max_len):
new_path = f"{path}[{i}]" if path else f"[{i}]"
if i >= len(x):
result.append(new_path)
elif i >= len(y):
result.append(new_path)
else:
result.extend(_diff(new_path, x[i], y[i]))
return result
# Handle scalars (int, float, str, bool, None)
if x != y:
return [path] if path else []
return []
return sorted(_diff("", a, b))Served via llama.cpp Vulkan · 12.2 tok/s · 2.6 GB RAM · coding total 105/126
No failures.
No failures.
Served via llama.cpp Vulkan · 72.3 tok/s · 0.2 GB RAM · coding total 104/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.
(no code extracted)Served via llama.cpp Vulkan · 17.5 tok/s · 2.9 GB RAM · coding total 104/126
No failures.
No failures.
Served via llama.cpp Vulkan · 63.7 tok/s · 0.3 GB RAM · coding total 103/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(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 Vulkan · 86.2 tok/s · 0.3 GB RAM · coding total 102/126
No failures.
No failures.
Served via llama.cpp Vulkan · 12.5 tok/s · 2.6 GB RAM · coding total 100/126
No failures.
No failures.
Served via llama.cpp Vulkan · 14.7 tok/s · 0.5 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}]"
if x != y:
diffs.append(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}]"
if x != y:
diffs.append(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}]"
if x != y:
diffs.append(new_path)
else:
if a != b:
diffs.append(path)
return diffs
return sorted(_diff(a, b, ""))Served via llama.cpp Vulkan · 58.7 tok/s · 1.2 GB RAM · coding total 95/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, path=""):
result = []
if type(a) != type(b):
result.append(path if path else "<root>")
return result
if isinstance(a, dict):
all_keys = set(a.keys()) | set(b.keys())
for key in sorted(all_keys):
new_path = f"{path}.{key}" if path else key
result.extend(json_diff(a.get(key), b.get(key), new_path))
elif isinstance(a, list):
max_len = max(len(a), len(b))
for i in range(max_len):
new_path = f"{path}[{i}]"
val_a = a[i] if i < len(a) else None
val_b = b[i] if i < len(b) else None
if val_a != val_b:
result.append(new_path)
else:
if a != b:
result.append(path if path else "<root>")
return resultServed via llama.cpp Vulkan · 58.5 tok/s · 1.2 GB RAM · coding total 94/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):
total = 0.0
with open(path, 'r') as f:
reader = csv.DictReader(f)
for row in reader:
total += float(row[col])
return totaldef csv_column_sum(path, col):
total = 0.0
with open(path, 'r') as f:
reader = csv.DictReader(f)
for row in reader:
total += float(row[col])
return totaldef csv_column_sum(path, col):
total = 0.0
with open(path, 'r') as f:
reader = csv.DictReader(f)
for row in reader:
total += float(row[col])
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, prefix=""):
"""
Compares two JSON-like structures (dicts, lists, scalars).
Returns a sorted list of dotted key paths where they differ.
"""
diffs = []
# If both are dicts, recurse
if isinstance(a, dict) and isinstance(b, dict):
all_keys = set(a.keys()) | set(b.keys())
for key in all_keys:
path = f"{prefix}.{key}" if prefix else key
if key not in a:
diffs.append(f"{path} (missing in left)")
elif key not in b:
diffs.append(f"{path} (missing in right)")
else:
diffs.extend(json_diff(a[key], b[key], path))
else:
# For lists and scalars, compare as whole values
if a != b:
if prefix:
diffs.append(prefix)
else:
diffs.append("(root)")
return sorted(diffs)def json_diff(a, b, prefix=""):
"""
Compares two JSON-like structures (dicts, lists, scalars).
Returns a sorted list of dotted key paths where they differ.
"""
diffs = []
# If both are dicts, recurse
if isinstance(a, dict) and isinstance(b, dict):
all_keys = set(a.keys()) | set(b.keys())
for key in all_keys:
path = f"{prefix}.{key}" if prefix else key
if key not in a:
diffs.append(f"{path} (missing in left)")
elif key not in b:
diffs.append(f"{path} (missing in right)")
else:
diffs.extend(json_diff(a[key], b[key], path))
else:
# For lists and scalars, compare as whole values
if a != b:
if prefix:
diffs.append(prefix)
else:
diffs.append("(root)")
return sorted(diffs)def json_diff(a, b, prefix=""):
"""
Compares two JSON-like structures (dicts, lists, scalars).
Returns a sorted list of dotted key paths where they differ.
"""
diffs = []
# If both are dicts, recurse
if isinstance(a, dict) and isinstance(b, dict):
all_keys = set(a.keys()) | set(b.keys())
for key in all_keys:
path = f"{prefix}.{key}" if prefix else key
if key not in a:
diffs.append(f"{path} (missing in left)")
elif key not in b:
diffs.append(f"{path} (missing in right)")
else:
diffs.extend(json_diff(a[key], b[key], path))
else:
# For lists and scalars, compare as whole values
if a != b:
if prefix:
diffs.append(prefix)
else:
diffs.append("(root)")
return sorted(diffs)Served via llama.cpp Vulkan · 22.2 tok/s · 2.4 GB RAM · coding total 93/126
No failures.
No failures.
Served via llama.cpp Vulkan · 12.5 tok/s · 2.6 GB RAM · coding total 93/126
No failures.
No failures.
Served via llama.cpp Vulkan · 48.3 tok/s · 0.4 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
total = 0.0
for row in reader:
if len(row) > col:
try:
total += float(row[col])
except ValueError:
pass
return totalimport 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):
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 isinstance(x, dict) and isinstance(y, dict):
for k in sorted(set(x) | set(y)):
if k not in x:
diffs.append(path + "." + k)
elif k not in y:
diffs.append(path + "." + k)
else:
compare(x[k], y[k], path + "." + k)
elif 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 Vulkan · 85.0 tok/s · 0.3 GB RAM · coding total 87/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):
# Build reverse dependency map and in-degree count
reverse_deps = {node: [] for node in deps}
in_degree = {node: 0 for node in deps}
# Initialize in-degree for all nodes
for node, dependencies in deps.items():
for dep in dependencies:
if dep not in reverse_deps:
reverse_deps[dep] = []
reverse_deps[dep].append(node)
in_degree[dep] = in_degree.get(dep, 0) + 1
# Add nodes that are only dependencies (no outgoing edges)
all_nodes = set(in_degree.keys())
for node in reverse_deps:
if node not in all_nodes:
in_degree[node] = 0
# Find all nodes with no incoming edges
queue = [node for node, degree in in_degree.items() if degree == 0]
result = []
while queue:
node = queue.pop(0)
result.append(node)
# Remove node and update in-degrees
for neighbor in reverse_deps.get(node, []):
in_degree[neighbor] -= 1
if in_degree[neighbor] == 0:
queue.append(neighbor)
# Check for cycles
if len(result) != len(in_degree):
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(obj_a, obj_b, path=""):
diffs = []
if type(obj_a) != type(obj_b):
diffs.append(path)
elif isinstance(obj_a, dict):
all_keys = set(obj_a.keys()) | set(obj_b.keys())
for key in sorted(all_keys):
new_path = f"{path}.{key}" if path else key
if key not in obj_a:
diffs.append(new_path)
elif key not in obj_b:
diffs.append(new_path)
else:
diffs.extend(_diff(obj_a[key], obj_b[key], new_path))
elif isinstance(obj_a, list):
if len(obj_a) != len(obj_b):
diffs.append(path)
else:
for i, (item_a, item_b) in enumerate(zip(obj_a, obj_b)):
new_path = f"{path}[{i}]"
diffs.extend(_diff(item_a, item_b, new_path))
else:
if obj_a != obj_b:
diffs.append(path)
return diffs
return sorted(_diff(a, b))def json_diff(a, b):
def _diff(obj_a, obj_b, path=""):
diffs = []
if type(obj_a) != type(obj_b):
diffs.append(path)
elif isinstance(obj_a, dict):
all_keys = set(obj_a.keys()) | set(obj_b.keys())
for key in sorted(all_keys):
new_path = f"{path}.{key}" if path else key
if key not in obj_a:
diffs.append(new_path)
elif key not in obj_b:
diffs.append(new_path)
else:
diffs.extend(_diff(obj_a[key], obj_b[key], new_path))
elif isinstance(obj_a, list):
if len(obj_a) != len(obj_b):
diffs.append(path)
else:
for i, (item_a, item_b) in enumerate(zip(obj_a, obj_b)):
new_path = f"{path}[{i}]"
diffs.extend(_diff(item_a, item_b, new_path))
else:
if obj_a != obj_b:
diffs.append(path)
return diffs
return sorted(_diff(a, b))def json_diff(a, b):
def _diff(obj_a, obj_b, path=""):
diffs = []
if type(obj_a) != type(obj_b):
diffs.append(path)
elif isinstance(obj_a, dict):
all_keys = set(obj_a.keys()) | set(obj_b.keys())
for key in sorted(all_keys):
new_path = f"{path}.{key}" if path else key
if key not in obj_a:
diffs.append(new_path)
elif key not in obj_b:
diffs.append(new_path)
else:
diffs.extend(_diff(obj_a[key], obj_b[key], new_path))
elif isinstance(obj_a, list):
if len(obj_a) != len(obj_b):
diffs.append(path)
else:
for i, (item_a, item_b) in enumerate(zip(obj_a, obj_b)):
new_path = f"{path}[{i}]"
diffs.extend(_diff(item_a, item_b, new_path))
else:
if obj_a != obj_b:
diffs.append(path)
return diffs
return sorted(_diff(a, b))Served via llama.cpp Vulkan · 10.2 tok/s · 0.6 GB RAM · coding total 86/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.
(no code extracted)from collections import deque
def topological_sort(deps):
nodes = set(deps.keys())
for dep_list in deps.values():
nodes.update(dep_list)
nodes = list(nodes)
adj = {node: [] for node in nodes}
in_degree = {node: 0 for node in nodes}
for node in nodes:
dep_list = deps.get(node, [])
unique_deps = set(dep_list)
in_degree[node] = len(unique_deps)
for dep in unique_deps:
adj[dep].append(node)
queue = deque(node for node in nodes if in_degree[node] == 0)
result = []
while queue:
current = queue.popleft()
result.append(current)
for neighbor in adj[current]:
in_degree[neighbor] -= 1
if in_degree[neighbor] == 0: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 Vulkan · 42.2 tok/s · 0.2 GB RAM · coding total 82/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 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()):
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()) + [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()) + [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]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 Vulkan · 9.6 tok/s · 2.1 GB RAM · coding total 64/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}"
for i in range(max(len(a), len(b)))
for subpath in diff_path(f"{path}[i]", a[i] if i < len(a) else None, b[i])
]
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}"
for i in range(max(len(a), len(b)))
for subpath in diff_path(f"{path}[i]", a[i] if i < len(a) else None, b[i])
]
else:
return [path] if a != b else []
return diff_path("", a, b)