Facebook Sign in | Join
Getting Started with Adobe After Effects - Part 6: Motion Blur
First Time? You can support us by signing up. It takes only 5 seconds. Click here to sign up. If you already have an account, click here to login.

Solution to TSQL Challenge 56 - Create a Sierpinski carpet using TSQL By makus

with moveto as (
	select id = 1, carpet = cast('X' as varchar(max)), [level] = 0, max_row = max([level])
	from tc56 t
	union all
	select id = tt.n,		
		case 
			when tt.n between power(3, [level]) + 1 and 2 * power(3, [level]) 
			then carpet + replicate(' ', power(3, [level])) + carpet
			else cast(replicate(carpet,3) as varchar(max)) 
		end, 
		[level] + 1,
		max_row
	from tsqlc_tally tt
	inner join moveto m
		on
			case 
				when tt.n % power(3, [level]) = 0 
				then power(3, [level]) else tt.n % power(3, [level]) 
			end = m.id 
	where n between	1 and power(3, [level] + 1) and [level] < max_row)
select t.id, m.id row, m.carpet 
from tc56 t
inner join moveto m
	on t.[level] = m.[level] 
order by t.id, m.id

Performance stats of the above solution

Sr# StartTime                 Reads      Writes         CPU Duration 
--- ------------------- ----------- ----------- ----------- -------- 
  1 Jan 15 2011  4:33PM      290873        2243        1406    1.518
  2 Jan 15 2011  4:57PM      290819        2237        1406    1.496
  3 Jan 15 2011  5:20PM      290873        2243        1406    1.516
  4 Jan 15 2011  5:44PM      290819        2237        1344    1.487
  5 Jan 15 2011  6:08PM      290873        2243        1406    1.525

Copyright © Rivera Informatic Private Ltd.