We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Draw The Triangle 2
Draw The Triangle 2
Sort by
recency
|
918 Discussions
|
Please Login in order to post a comment
With recursive increase as(
Select 1 as base
union all
select base+1 as base from increase where (base)<40 )
select LPAD('',base, '* ') from increase where mod(base,2)=0;
--This is my solution in Oracle SELECT LPAD('* ', LEVEL * 2, '* ') FROM DUAL CONNECT BY LEVEL <= 20;
WITH pattern AS ( SELECT 1 AS N UNION ALL SELECT N + 1 FROM pattern WHERE N < 20 ) SELECT REPLICATE(' *',N) FROM pattern OPTION (MAXRECURSION 0)
DECLARE @start_num INT, @end_num INT, @iterator INT, @pattern varchar(100) = '' SET @iterator = 1 SET @end_num = 20 -- Set to 20 for P(20)
WHILE @iterator <= @end_num BEGIN SET @start_num = 1 set @pattern = '' WHILE @start_num <= @iterator BEGIN set @pattern = @pattern + ' *' SET @start_num = @start_num + 1 END PRINT(@pattern) SET @iterator = @iterator + 1 END;
for MSSQL WITH pattern(n) AS ( SELECT 1 UNION ALL SELECT n + 1 FROM pattern WHERE n < 20 ) SELECT replicate('* ', n) FROM pattern;