Round #672

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

Prompt

Calculate the gap in days between consecutive logins per user using LAG.

Zero-point index (what the engine surfaced)

ZPI-ZPI-0021 | 2026-05-10T08:41:07Z Calculate the gap in days between consecutive logins per user using LAG. ZERO POINT — 3 entries (structural invariants) ● hsl(7.18, 100%, 50%) class [feature] ● hsl(0.00, 100%, 50%) public [feature] ● hsl(84.10, 100%, 50%) namespace [feature] UNOBSERVED — 0 entries (implied truths) OBSERVED — 2 entries (explicit in request) ◉ hsl(85.13, 100%, 50%) using [feature] ◉ hsl(234.87, 100%, 50%) using [feature] COMPLEXITY │ 5 entries │ spread: 150° │ band: LOW

Baseline response (no ZPI)

To calculate the gap in days between consecutive logins per user using LAG in SQL, you can follow these steps: 1. **Order the data by user and login date**. 2. **Use the LAG function to get the previous login date for each user**. 3. **Calculate the difference between the current login date and the previous login date**. Here's an example of how you can achieve this in SQL: ```sql WITH OrderedLogins AS ( SELECT UserID, LoginDate, LAG(LoginDate) OVER (PARTITION BY UserID ORDER BY LoginDate) AS PreviousLoginDate FROM UserLogins ) SELECT UserID, LoginDate, PreviousLoginDate, CASE WHEN PreviousLoginDate IS NULL THEN NULL -- No previous login for the first entry ELSE DATEDIFF(day, PreviousLoginDate, LoginDate) END AS GapInDays FROM OrderedLogins; ``` ### Explanation: 1. **CTE (Common Table Expression) `OrderedLogins`**: - This CTE orders the logins by `UserID` and `LoginDate`. - It uses the `LAG` function to get the previous login date for each user. 2. **Main Query**: - The main query selects the `UserID`, `LoginDate`, and `PreviousLoginDate`. - It calculates the gap in days using the `DATEDIFF` function. - If there is no previous login (i.e., it's the first entry for a user), the gap is set to `NULL`. ### Example Data: Assume you have a table `UserLogins` with the following data: | UserID | LoginDate | |--------|-----------------| | 1 | 2023-01-01 | | 1 | 2023-01-15 | | 1 | 2023-02-01 | | 2 | 2023-01-05 | | 2 | 2023-01-20 | ### Result: The query will produce the following result: | UserID | LoginDate | PreviousLoginDate | GapInDays | |--------|-----------------|-------------------|-----------| | 1 | 2023-01-01 | NULL | NULL | | 1 | 2023-01-15 | 2023-01-01 | 14 | | 1 | 2023-02-01 | 2023-01-15 | 16 | | 2 | 2023-01-05 | NULL | NULL | | 2 | 2023-01-20 | 2023-01-05 | 15 | This result shows the gap in days between consecutive logins for each user.

Enhanced response (with ZPI)

To calculate the gap in days between consecutive logins per user using LAG, we can utilize SQL Server's `LAG` function. This function allows us to access data from a previous row in the same result set without self-joining the table. Here is an example of how you can implement this: ```sql WITH LoginData AS ( SELECT UserID, LoginDate, LAG(LoginDate) OVER (PARTITION BY UserID ORDER BY LoginDate) AS PreviousLoginDate FROM UserLogins ) SELECT UserID, LoginDate, CASE WHEN PreviousLoginDate IS NULL THEN NULL -- First login for the user ELSE DATEDIFF(day, PreviousLoginDate, LoginDate) END AS GapInDays FROM LoginData; ``` ### Explanation: 1. **CTE (Common Table Expression) `LoginData`:** - We use a CTE to calculate the previous login date for each user. - The `LAG` function is used with the `PARTITION BY UserID` clause to ensure that we are looking at the previous login date within each user's partition. - The `ORDER BY LoginDate` ensures that the logins are ordered chronologically. 2. **Main Query:** - We select the `UserID`, `LoginDate`, and calculate the gap in days using the `DATEDIFF` function. - If it is the first login for a user (`PreviousLoginDate IS NULL`), we set the gap to `NULL`. ### Example Data: Assume you have a table `UserLogins` with the following data: | UserID | LoginDate | |--------|-----------------| | 1 | 2023-04-01 | | 1 | 2023-04-15 | | 1 | 2023-04-30 | | 2 | 2023-04-05 | | 2 | 2023-04-20 | ### Result: The query will produce the following result: | UserID | LoginDate | GapInDays | |--------|-----------------|-----------| | 1 | 2023-04-01 | NULL | | 1 | 2023-04-15 | 14 | | 1 | 2023-04-30 | 15 | | 2 | 2023-04-05 | NULL | | 2 | 2023-04-20 | 15 | This result shows the gap in days between consecutive logins for each user.

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
Same
V4qwen2.5-coder-3b-instruct
Better
V5openrouter/qwen/qwen3-235b-a22b-2507
Same
V7qwen2.5-coder-7b-instruct
Same
V8openai/gpt-4.1
Same
V9anthropic/claude-opus-4-7
Same
V12openai/gpt-4o
Same

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