Predict the output

  • DECLARE @NUMBER INT = 10

    DECLARE @DATA CHAR(1)='#'

    DECLARE @OTHERDATA CHAR(1)='@'

    DECLARE @SPACEDATA CHAR(1)=' '

    DECLARE @TEXT VARCHAR(MAX)

    DECLARE @LEFT INT

    DECLARE @RIGHT INT = 1

    DECLARE @TEXTRIGHT INT

    WHILE(@NUMBER>0)

    BEGIN

    SET @TEXT =''

    SET @TEXTRIGHT = @RIGHT

    IF(@NUMBER%2=0)

    BEGIN

    SET @LEFT = FLOOR(@NUMBER/2)

    END

    ELSE

    BEGIN

    SET @NUMBER = @NUMBER - 1

    CONTINUE

    END

    WHILE(@LEFT>0)

    BEGIN

    IF(@LEFT>1)

    BEGIN

    SET @TEXT += @SPACEDATA

    END

    ELSE

    BEGIN

    WHILE(@TEXTRIGHT>0)

    BEGIN

    IF(@TEXTRIGHT%2=0)

    SET @TEXT += @OTHERDATA

    ELSE

    SET @TEXT += @DATA

    SET @TEXTRIGHT = @TEXTRIGHT - 1

    END

    PRINT(@TEXT)

    END

    SET @LEFT = @LEFT - 1

    END

    SET @NUMBER = @NUMBER - 1

    IF(@RIGHT=1)

    BEGIN

    SET @RIGHT = 3

    END

    ELSE

    BEGIN

    SET @RIGHT = 2+@RIGHT

    END

    END

    rkaram

  • can't really predict the output, since this poll has all incorrect answers.

    kudos for the easily copy-and-pasteable code, it produces results that basically looks like a christmas tree, i guess.

    but the results are 5 lines that don't appear in your poll

    #

    #@#

    #@#@#

    #@#@#@#

    #@#@#@#@#

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Polls won't allow multi-line answers, but it's a nice output 🙂

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply