T-SQL, (981 9701,168 1,168139 bytes)
WITH g AS(SELECT 1 AS n UNION ALL SELECT n+1 FROM g WHERE n+1<61),B as(SELECT cast(cast(n&32 as bit)as CHAR(1))+cast(cast(n&16 as bit)as CHAR(1))+cast(cast(n&8 as bit)as CHAR(1))+cast(cast(n&4 as bit)as CHAR(1))+cast(cast(n&2 as bit)as CHAR(1))+cast(cast(n&1 as bit)as CHAR(1))as b FROM g),NP ASas(SELECT 0 AS n UNION ALL SELECT n+1* FROMfrom N(values(1), WHERE(2), n+1<=5(4),P as(SELECT8), power(216),n (32)) as Q(p FROM N)),S as(select distinct p,p+(substring(b,6,1)*1)*(case when p=1 then 0 else 1 end)+(substring(b,5,1)*2)*(case when p=2 then 0 else 1 end)+(substring(b,4,1)*4)*(case when p=4 then 0 else 1 end)+(substring(b,3,1)*8)*(case when p=8 then 0 else 1 end)+(substring(b,2,1)*16)*(case when p=16 then 0 else 1 end)+(substring(b,1,1)*32)*(case when p=32 then 0 else 1 end)as e from P cross apply B),D as(select * from S where e>=p and e<61),R as(select p,(row_number()over(partition by p order by cast(e as int)))%5 as r,e from D),H as(select k.p,'['+stuff((select','+cast(l.e as varchar)from R l where l.p=k.p and l.r=k.r for xml path('')),1,1,'')+']'as s from R k group by k.p,k.r)select stuff((select','+cast(x.s as varchar)from H x where x.p=z.p for xml path('')),1,1,'')from H z group by z.p
WITH gen -- numbers 1 to 60
AS (
SELECT 1 AS num
UNION ALL
SELECT num+1 FROM gen WHERE num+1<=60
),
BINARIES -- string representations of binaries 000001 through 111111
as (
SELECT
+cast( cast(num & 32 as bit) as CHAR(1))
+cast( cast(num & 16 as bit) as CHAR(1))
+cast( cast(num & 8 as bit) as CHAR(1))
+cast( cast(num & 4 as bit) as CHAR(1))
+cast( cast(num & 2 as bit) as CHAR(1))
+cast(cast(num & 1 as bit) as CHAR(1)) as binry FROM gen
),
NPOWERS -- numbers 0 through 5
AS (
first SELECT6 0powers ASof n2
UNIONas ALL(
SELECT n+1 FROM N* WHEREfrom n+1<=5
(values(1),
POWERS -- powers of 2 based on N (2 to the power of zero), through 2 to the power of 5(4)
as, (
SELECT
power8), (216),n (32)) as Q(powr FROM N)
),
SETELEMENTS -- cross apply the six powers of 2 against the binaries
-- returns 2 cols. col 1 = the power of 2 in question.
-- col 2 is calculated as that power of 2 plus the sum of each power of 2 other than the current row's power value,
-- but only where a given power of 2 is switched "on" in the binary string,
-- ie. where the first digit in the string represents 32, the second represents 16 and so on.
-- That is, if the binary is 100100 then the number will be
-- the sum of (32 x 1) + (16 x 0) + (8 x 0) + (4 x 1) + (2 x 0) + (1 x 0)
-- but if the current row's power is 32 or 4, then just that number (32 or 4) is excluded from the sum.
-- rows are distinct.
as (
select distinct powr,
powr+
(substring(binry,6,1) * 1) * (case when powr = 1 then 0 else 1 end)
+(substring(binry,5,1) * 2) * (case when powr = 2 then 0 else 1 end)
+(substring(binry,4,1) * 4) * (case when powr = 4 then 0 else 1 end)
+(substring(binry,3,1) * 8) * (case when powr = 8 then 0 else 1 end)
+(substring(binry,2,1) * 16) * (case when powr = 16 then 0 else 1 end)
+(substring(binry,1,1) * 32) * (case when powr = 32 then 0 else 1 end) as elt
from POWERS cross apply BINARIES
),
DISTINCTELEMENTS -- purge calculated numbers smaller than the power of 2 or greater than 60
as (
select * from SETELEMENTS where elt >= powr and elt < 61
)--,
,
ROWNUMBERED -- for each power, number the rows repeatedly from 0 through 5, then back to 0 through 5 again, etc
as (
select powr, (row_number() over (partition by powr order by cast(elt as int)))%5 as r, elt from DISTINCTELEMENTS
),
GROUPEDSETS -- for each row number, within each power, aggregate the numbers as a comma-delimited list and wrap in square brackets - the inner arrays
as (
select r1.powr, '['+stuff((select ',' + cast(r2.elt as varchar) from ROWNUMBERED r2 where r2.powr = r1.powr and r2.r = r1.r for xml path('')),1,1,'')+']' as s
from ROWNUMBERED r1
group by r1.powr,r1.r
)
select -- now aggregate all the inner arrays per power
stuff((select ',' + cast(g2.s as varchar) from GROUPEDSETS g2 where g2.powr = g1.powr for xml path('')),1,1,'')
from GROUPEDSETS g1
group by g1.powr
Shorter to hard-code arrays?
Yes.
Byte me.