Round #664

10 May 2026, 08:36· csharp· qwen2.5-coder-7b-instruct· r13-clean-hints
Complexity
band 0
ZP / UO / OBS
0 / 0 / 0
Journey weight
0
Lightshift ΔL

Prompt

Find customers who placed orders in consecutive calendar months.

Zero-point index (what the engine surfaced)

ZPI-ZPI-0013 | 2026-05-10T08:36:51Z Find customers who placed orders in consecutive calendar months. ZERO POINT — 0 entries (structural invariants) UNOBSERVED — 0 entries (implied truths) OBSERVED — 0 entries (explicit in request) COMPLEXITY │ 0 entries │ spread: 0° │ band: LOW

Baseline response (no ZPI)

To find customers who placed orders in consecutive calendar months, you can use SQL to query your database. Below is an example of how you might write such a query assuming you have a table named `Orders` with columns `CustomerID`, `OrderDate`. ```sql WITH MonthlyOrders AS ( SELECT CustomerID, OrderDate, DATEPART(YEAR, OrderDate) AS OrderYear, DATEPART(MONTH, OrderDate) AS OrderMonth FROM Orders ), ConsecutiveMonths AS ( SELECT CustomerID, OrderYear, OrderMonth, LAG(OrderMonth) OVER (PARTITION BY CustomerID ORDER BY OrderYear, OrderMonth) AS PreviousOrderMonth FROM MonthlyOrders ) SELECT CustomerID, OrderYear, OrderMonth, PreviousOrderMonth FROM ConsecutiveMonths WHERE OrderMonth = PreviousOrderMonth + 1; ``` ### Explanation: 1. **MonthlyOrders CTE**: This Common Table Expression (CTE) extracts the year and month from each order date. 2. **ConsecutiveMonths CTE**: This CTE uses the `LAG` function to get the previous month's order for each customer. The `PARTITION BY CustomerID` ensures that we are looking at consecutive months per customer, and `ORDER BY OrderYear, OrderMonth` orders the months chronologically. 3. **Final SELECT**: Filters out the rows where the current month is exactly one more than the previous month, indicating consecutive months. ### Notes: - This query assumes that your database supports window functions like `LAG`. If you're using a database that doesn't support these (like SQL Server), you might need to use a different approach. - The `DATEPART` function extracts the year and month from the date. Adjust this if your database uses different functions for extracting parts of a date. ### Example in C#: If you want to execute this query using C#, you can use ADO.NET or Entity Framework. Below is an example using ADO.NET: ```csharp using System; using System.Data.SqlClient; class Program { static void Main() { string connectionString = "your_connection_string_here"; string query = @" WITH MonthlyOrders AS ( SELECT CustomerID, OrderDate, DATEPART(YEAR, OrderDate) AS OrderYear, DATEPART(MONTH, OrderDate) AS OrderMonth FROM Orders ), ConsecutiveMonths AS ( SELECT CustomerID, OrderYear, OrderMonth, LAG(OrderMonth) OVER (PARTITION BY CustomerID ORDER BY OrderYear, OrderMonth) AS PreviousOrderMonth FROM MonthlyOrders ) SELECT CustomerID, OrderYear, OrderMonth, PreviousOrderMonth FROM ConsecutiveMonths WHERE OrderMonth = PreviousOrderMonth + 1;"; using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { int customerID = reader.GetInt32(0); int orderYear = reader.GetInt32(1); int orderMonth = reader.GetInt32(2); int previousOrderMonth = reader.GetInt32(3); Console.WriteLine($"Customer ID: {customerID}, Order Year: {orderYear}, Order Month: {orderMonth}, Previous Order Month: {previousOrderMonth}"); } } } } ``` Replace `"your_connection_string_here"` with your actual database connection string. This code will execute the query and print out the results to the console.

Enhanced response (with ZPI)

To find customers who placed orders in consecutive calendar months, we can use LINQ to process order data and identify those customers whose orders span multiple consecutive months. Below is a complete implementation using C# with proper error handling and dependency injection (DI) registration. ### Implementation 1. **Define the necessary classes:** ```csharp public class Order { public int CustomerId { get; set; } public DateTime OrderDate { get; set; } } public interface IOrderRepository { Task<List<Order>> GetOrdersAsync(int customerId); } ``` 2. **Implement the repository:** ```csharp public class OrderRepository : IOrderRepository { private readonly List<Order> _orders; public OrderRepository() { // Simulated data for demonstration purposes _orders = new List<Order> { new Order { CustomerId = 1, OrderDate = new DateTime(2023, 1, 15) }, new Order { CustomerId = 1, OrderDate = new DateTime(2023, 2, 10) }, new Order { CustomerId = 1, OrderDate = new DateTime(2023, 4, 5) }, new Order { CustomerId = 2, OrderDate = new DateTime(2023, 1, 20) }, new Order { CustomerId = 2, OrderDate = new DateTime(2023, 3, 15) } }; } public async Task<List<Order>> GetOrdersAsync(int customerId) { return _orders.Where(o => o.CustomerId == customerId).ToList(); } } ``` 3. **Create a service to find customers with consecutive orders:** ```csharp public class CustomerService { private readonly IOrderRepository _orderRepository; public CustomerService(IOrderRepository orderRepository) { _orderRepository = orderRepository; } public async Task<List<int>> GetCustomersWithConsecutiveOrdersAsync() { var customersWithConsecutiveOrders = new List<int>(); var allCustomers = await _orderRepository.GetOrdersAsync(0); // Assuming 0 is a placeholder for all customers foreach (var customerId in allCustomers.Select(o => o.CustomerId).Distinct()) { var orders = await _orderRepository.GetOrdersAsync(customerId); if (orders.Count < 2) continue; var orderDates = orders.Select(o => o.OrderDate.Month).OrderBy(m => m).ToList(); for (int i = 1; i < orderDates.Count; i++) { if (orderDates[i] != orderDates[i - 1] + 1) { customersWithConsecutiveOrders.Add(customerId); break; } } } return customersWithConsecutiveOrders; } } ``` 4. **Register the services with dependency injection:** ```csharp public class Startup { public void ConfigureServices(IServiceCollection services) { services.AddScoped<IOrderRepository, OrderRepository>(); services.AddScoped<CustomerService>(); // Other service registrations... } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { // Middleware configuration... } } ``` 5. **Use the service in a controller or other part of your application:** ```csharp public class CustomersController : ControllerBase { private readonly CustomerService _customerService; public CustomersController(CustomerService customerService) { _customerService = customerService; } [HttpGet("consecutive-orders")] public async Task<IActionResult> GetCustomersWithConsecutiveOrders() { try { var customers = await _customerService.GetCustomersWithConsecutiveOrdersAsync(); return Ok(customers); } catch (Exception ex) { return StatusCode(500, $"An error occurred: {ex.Message}"); } } } ``` ### Explanation 1. **Order Class:** Represents an order with a customer ID and an order date. 2. **IOrderRepository Interface:** Defines the method to retrieve orders for a given customer. 3. **OrderRepository Class:** Implements the repository interface, providing simulated data for demonstration purposes. 4. **CustomerService Class:** Contains the logic to find customers who placed orders in consecutive months. 5. **Startup Class:** Registers the services with dependency injection. 6. **CustomersController Class:** Uses the `CustomerService` to retrieve and return customers with consecutive orders. This implementation ensures that the code is complete, idiomatic, and follows best practices for error handling and dependency injection.

Grader chain

Each grader reads the same baseline + enhanced pair and casts an independent verdict. Disagreement is the framework's own signal — not noise to be averaged away.

V1samba/Meta-Llama-3.3-70B-Instruct
Better
V4qwen2.5-coder-3b-instruct
Better
V5openrouter/qwen/qwen3-235b-a22b-2507
Better
V7qwen2.5-coder-7b-instruct
Better
V8openai/gpt-4.1
Better
V9anthropic/claude-opus-4-7
Worse
V12openai/gpt-4o
Better

Comments

Our grader said what it said. What do you say? Comment as a guest below.

No comments yet. Be the first to say what you make of this round.

← back to all rounds