Skip to content Skip to sidebar Skip to footer

How Create All Pieces Combinations

Im trying to solve a puzzle, by using some prunning and brute force I reach level 48. But now thinking use some Memoization to reuse the calculations. I have some tables: puzzles:

Solution 1:

Using Erwin Brandstetter solution, just add unnest to convert array to rows.

WITH cte as (
    SELECT row_number() over () as rn, *
    FROM f_combos(array(SELECT piece_id FROM pieces ORDER BY piece_id)) 
)
SELECT rn, unnest( f_combos ) AS id
FROM cte    
ORDER BY 1;

Post a Comment for "How Create All Pieces Combinations"