Piexplode

Generating Seeded Tours in SQL

Dec 17th, 2021
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.58 KB | None | 0 0
  1. DECLARE @Rounds INT = 3;
  2.  
  3. WITH Slots AS (SELECT 1 AS RecursionLevel, 1 AS Num1, 2 AS Num2
  4.                 UNION ALL
  5.                SELECT RecursionLevel + 1 AS RecursionLevel, Num1, POWER(2,RecursionLevel+1) + 1 - Num1
  6.                  FROM Slots
  7.                 WHERE RecursionLevel < @Rounds
  8.                 UNION ALL
  9.                SELECT RecursionLevel + 1 AS RecursionLevel, Num2, POWER(2,RecursionLevel+1) + 1 - Num2
  10.                  FROM Slots
  11.                 WHERE RecursionLevel < @Rounds)
  12. SELECT @Rounds + 1 - RecursionLevel AS [Round], Num1, Num2
  13.   FROM Slots
  14.  ORDER BY 1
  15.  
Add Comment
Please, Sign In to add comment