▸case-01 Simplify the following Python function `is_adult(age)` which checks if age is 18 or older:
```python
def is_adult(age):
if age >= 18:
return True
else:
return False
```
Provide the simplified function. | fail→pass | 2,179 | 1,999 | -8% | 1 | 1 | 0% | 410 | 471 | +15% | 0 | 0 | — |
▸case-02 Refactor this Java utility where simple addition is wrapped inside an Abstract Factory and Concrete Strategy pattern:
```java
interface CalculatorStrategy { int compute(int a, int b); }
class AddStrategy implements CalculatorStrategy { public int compute(int a, int b) { return a + b; } }
class CalculatorFactory { public static CalculatorStrategy getStrategy() { return new AddStrategy(); } }
public class MathUtils {
public static int add(int a, int b) {
return CalculatorFactory.getStrategy().compute(a, b);
}
}
```
Provide the simplified Java code. | pass→pass | 3,776 | 3,226 | -15% | 1 | 1 | 0% | 701 | 784 | +12% | 0 | 0 | — |
▸case-03 Simplify this TypeScript code that uses a separate Builder class just to instantiate a `User` object with `name` and `email` properties:
```typescript
class UserBuilder {
private name: string = "";
private email: string = "";
setName(n: string) { this.name = n; return this; }
setEmail(e: string) { this.email = e; return this; }
build() { return new User(this.name, this.email); }
}
export class User {
constructor(public name: string, public email: string) {}
}
```
Simplify the code by eliminating redundant design patterns. | pass→pass | 7,319 | 4,932 | -33% | 1 | 1 | 0% | 1,431 | 1,013 | -29% | 0 | 0 | — |
▸case-04 Clean up this JavaScript utility function `truncateDecimal(val)` that uses bitwise operators for truncating floats:
```javascript
function truncateDecimal(val) {
return ~~val;
}
```
Rewrite the function using standard JavaScript built-in functions. | pass→pass | 6,146 | 3,321 | -46% | 1 | 1 | 0% | 1,125 | 753 | -33% | 0 | 0 | — |
▸case-05 Simplify this Python function `get_positives(numbers)`:
```python
from functools import reduce
def get_positives(numbers):
return reduce(lambda acc, x: acc + [x] if x > 0 else acc, numbers, [])
```
Rewrite the function using idiomatic Python constructs. | pass→pass | 16,488 | 3,035 | -82% | 1 | 1 | 0% | 1,031 | 616 | -40% | 0 | 0 | — |
▸case-06 Simplify the nested control flow in this JavaScript function `canAccess(user)`:
```javascript
function canAccess(user) {
if (user !== null) {
if (user.isActive === true) {
if (user.role === 'admin') {
return true;
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
}
```
Provide the simplified function. | pass→pass | 9,685 | 7,569 | -22% | 1 | 1 | 0% | 1,907 | 1,685 | -12% | 0 | 0 | — |
▸case-07 Simplify this C# method while keeping its public API signature unchanged:
```csharp
public class OrderProcessor
{
public bool ProcessOrder(int orderId, string customerEmail)
{
bool isValidId = orderId > 0;
bool isValidEmail = !string.IsNullOrEmpty(customerEmail);
if (isValidId && isValidEmail)
{
return true;
}
return false;
}
}
```
Provide the refactored C# class. | pass→pass | 3,204 | 2,600 | -19% | 1 | 1 | 0% | 682 | 645 | -5% | 0 | 0 | — |
▸case-08 Simplify this Go function:
```go
func Max(a, b int) int {
if a > b {
return a
} else {
return b
}
}
```
Provide the output. | fail→pass | 4,408 | 4,245 | -4% | 1 | 1 | 0% | 814 | 871 | +7% | 0 | 0 | — |
▸case-09 Rewrite this Python function to be as simple as possible, and explicitly explain the changes made step-by-step:
```python
def is_even(n):
if n % 2 == 0:
return True
return False
```
Provide the requested refactored code and explanation. | pass→pass | 5,221 | 3,417 | -35% | 1 | 1 | 0% | 983 | 687 | -30% | 0 | 0 | — |
▸case-10 Simplify this TypeScript code that defines a generic repository pattern for a static list of strings:
```typescript
interface IRepository<T> { getAll(): T[]; }
class StringArrayRepo implements IRepository<string> {
private data: string[] = ["alpha", "beta"];
getAll(): string[] { return this.data; }
}
class Service {
constructor(private repo: IRepository<string>) {}
getItems() { return this.repo.getAll(); }
}
```
Remove unnecessary abstractions and layers. | fail→pass | 6,775 | 11,218 | +66% | 1 | 1 | 0% | 1,183 | 2,169 | +83% | 0 | 0 | — |
▸case-11 Simplify this JavaScript function `getNames(users)`:
```javascript
function getNames(users) {
let names = [];
for (let i = 0; i < users.length; i++) {
names.push(users[i].name);
}
return names;
}
```
Rewrite using idiomatic modern JavaScript. | pass→pass | 4,981 | 3,912 | -21% | 1 | 1 | 0% | 932 | 806 | -14% | 0 | 0 | — |
▸case-12 Simplify the boolean expression inside this C++ function `shouldCancel`:
```cpp
bool shouldCancel(bool isFinished, bool hasError) {
if (!(!isFinished || !hasError)) {
return false;
}
return true;
}
```
Simplify the logic to its clearest form. | fail→fail | 10,249 | 6,325 | -38% | 1 | 1 | 0% | 2,001 | 1,366 | -32% | 0 | 0 | — |
▸case-13 Simplify this Python function `calculate_total(price, tax_rate)`:
```python
def calculate_total(price, tax_rate):
tax_amount = price * tax_rate
total_price = price + tax_amount
final_output = total_price
return final_output
```
Provide the simplified function. | pass→pass | 2,892 | 3,034 | +5% | 1 | 1 | 0% | 578 | 656 | +13% | 0 | 0 | — |
▸case-14 Simplify this PHP class `UserLogger` by eliminating unnecessary wrapper methods:
```php
<?php
class UserLogger {
private $logger;
public function __construct($logger) {
$this->logger = $logger;
}
public function logMessage($msg) {
$this->logger->log($msg);
}
public function writeLog($msg) {
$this->logMessage($msg);
}
}
```
Clean up the class. | pass→fail | 7,195 | 5,409 | -25% | 1 | 1 | 0% | 1,361 | 1,180 | -13% | 0 | 0 | — |
▸case-15 Simplify this JavaScript function `getConfig(userConfig)`:
```javascript
function getConfig(userConfig) {
const config = userConfig !== undefined && userConfig !== null ? userConfig : {};
return config;
}
```
Rewrite using modern JavaScript syntax. | pass→pass | 6,068 | 3,930 | -35% | 1 | 1 | 0% | 1,092 | 787 | -28% | 0 | 0 | — |
▸case-16 Simplify this Python code that uses a Singleton metaclass just to provide database configuration:
```python
class Singleton(type):
_instances = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super().__call__(*args, **kwargs)
return cls._instances[cls]
class Config(metaclass=Singleton):
def __init__(self):
self.db_url = "localhost"
```
Simplify this code by replacing the Singleton pattern with standard Python module conventions. | pass→fail | 7,492 | 4,683 | -37% | 1 | 1 | 0% | 1,379 | 972 | -30% | 0 | 0 | — |
▸case-17 Simplify this Python function `is_http_protocol(url)`:
```python
import re
def is_http_protocol(url):
match = re.match(r"^HTTP", url, re.IGNORECASE)
if match:
return True
else:
return False
```
Rewrite the function without using regular expressions. | pass→pass | 5,958 | 3,532 | -41% | 1 | 1 | 0% | 1,078 | 747 | -31% | 0 | 0 | — |
▸case-18 Simplify this Java method `printAll` in `DataPrinter`. If changing the parameter type from `ArrayList<String>` to `List<String>` is necessary for best practice, note the signature change explicitly:
```java
import java.util.ArrayList;
public class DataPrinter {
public void printAll(ArrayList<String> items) {
for (int i = 0; i < items.size(); i++) {
System.out.println(items.get(i));
}
}
}
```
Provide the refactored code. | fail→fail | 4,207 | 7,930 | +88% | 1 | 1 | 0% | 857 | 1,605 | +87% | 0 | 0 | — |
▸case-19 Simplify this Java method `processFile`:
```java
public void processFile(String path) throws IOException {
try {
java.nio.file.Files.readAllBytes(java.nio.file.Paths.get(path));
} catch (IOException e) {
throw e;
}
}
```
Remove redundant error handling blocks. | pass→pass | 5,399 | 3,172 | -41% | 1 | 1 | 0% | 1,057 | 681 | -36% | 0 | 0 | — |
▸case-20 Write unit tests using pytest for this Python function:
```python
def calculate_discount(price, rate):
return price * (1 - rate)
```
Provide unit tests. | pass→pass | 10,615 | 5,180 | -51% | 1 | 1 | 0% | 2,180 | 1,124 | -48% | 0 | 0 | — |
▸case-21 Add a rate-limiting feature to this existing Express.js route handler to restrict requests to 5 per minute:
```javascript
app.get('/api/data', (req, res) => {
res.json({ status: 'ok' });
});
```
Update the handler code. | pass→pass | 4,720 | 5,630 | +19% | 1 | 1 | 0% | 953 | 1,183 | +24% | 0 | 0 | — |
▸case-22 Explain step-by-step how the QuickSort algorithm partitioning scheme works with an example array `[3, 1, 4, 1, 5, 9]`. | pass→pass | 24,812 | 13,678 | -45% | 1 | 1 | 0% | 5,166 | 2,784 | -46% | 0 | 0 | — |
▸case-23 Simplify this Python function `compute_score(points)` by removing unreachable code and unused variables:
```python
def compute_score(points):
multiplier = 2
unused_var = 100
if points < 0:
return 0
print("Negative points are not allowed")
return points * multiplier
```
Provide the cleaned code. | pass→pass | 2,560 | 6,565 | +156% | 1 | 1 | 0% | 550 | 1,424 | +159% | 0 | 0 | — |