#Does anyone know how to reverse this code?

57 messages · Page 1 of 1 (latest)

ionic briar
#
        {
        
            for(int j = 0; j <= i; j++)
            {
                
                stringBuffer.append(color1);
                
            }
            
            for(int j = i; j <= (size * 5); j++)
            {
                
                if(i == 0 || i == (size-1))
                {
                    
                    stringBuffer.append(color2);
                
                }
                else
                {
                    
                    stringBuffer.append(color3);                    
                    
                }
                
            }```
steady berryBOT
#

This post has been reserved for your question.

Hey @ionic briar! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

ionic briar
#

i want to make this

#

but i currently have this

#

which is why i want to reverse the code i have posted above (it's the second half of the flag

mossy spruce
#

what do you mean by "reverse"

#

oh

#

ffs discord scrolling

ionic briar
#

hahaha

mossy spruce
#

sec

ionic briar
#

kk cool thanks!

mossy spruce
#

what are color1, color2, color3, size? just so i can get my bearings a bit quicker

#

also where are you adding newlines?

ionic briar
#

getVerticalBars(10, 12, 3, 'R', 'G', 'B');

#

right before the main for loop ends

mossy spruce
#

also what?

ionic briar
#
    {
        
        StringBuffer stringBuffer = new StringBuffer();
        
        for(int i = 0; i < size; i++)
        {
        
            for(int j = 0; j <= i; j++)
            {
                
                stringBuffer.append(color1);
                
            }
            
            for(int j = i; j <= (size * 5); j++)
            {
                
                if(i == 0 || i == (size-1))
                {
                    
                    stringBuffer.append(color2);
                
                }
                else
                {
                    
                    stringBuffer.append(color3);                    
                    
                }
                
            }
            stringBuffer.append("\n");
            
        }
        for(int i = 0; i < size; i++)
        {
        
            for(int j = 0; j <= i; j++)
            {
                
                stringBuffer.append(color1);
                
            }
            
            for(int j = i; j <= (size * 5); j++)
            {
                
                if(i == 0 || i == (size-1))
                {
                    
                    stringBuffer.append(color2);
                
                }
                else
                {
                    
                    stringBuffer.append(color3);                    
                    
                }
                
            }
            stringBuffer.append("\n");
            
        }```
mossy spruce
#

why would you not provide the entire code

ionic briar
#

people have gotten angry at me previously for posting too much code lol

steady berryBOT
#

Looks like you shared a lot of code, this may cause people to overlook problems in your code. To make it easier for them, make sure you only share lines that are relevant to your issue.

mossy spruce
#

try having a read at that

mossy spruce
#

the amount of code is fine, it's just really spread out (a lot more newlines than most people would prefer)

ionic briar
#

it's for comments haha (im dumb and add them in at the end lol)

mossy spruce
#

the main part is you need to show all the relevant stuff
truncate as much excess as you can, but don't remove stuff that's actually important

mossy spruce
ionic briar
#

i need to be very descriptive for the school im in

#

basically have to describe everything im doing

mossy spruce
#

no, why can't you just add the lines for the comments afterwards

ionic briar
#

idk tbh, it's just the way ive been doing it

mossy spruce
#

if you aren't going to be commenting along with writing the code, then just focus on the code, worry about comments later

ionic briar
#

yeah youre right

mossy spruce
#

anyways, you have 2 main loops, both using for (int i = 0; i < size; i++)
each of those correspond to half of the output you have rn

#

looks like the shape of it is dependant on i, so you need to change how i behaves, the order of values given as i

#

so the first loop would be unchanged, but for the second loop, since you need to reverse the order of how it iterates, you need to change where i starts and ends accordingly

#

you need it to iterate opposite the first loop, how can you do that

ionic briar
#

Would i be changing the starting point of i in the second half of the flag?

mossy spruce
#

yes

ionic briar
#

for(int i = size ; i > 0; i--)

#

hows this?

#

hey you there?

#
        {
        
            for(int j = 0; j <= i; j++)
            {
                
                stringBuffer.append(color1);
                
            }
            
            for(int j = i; j <= (size * 5); j++)
            {
                
                if(i == 1 || i == (size))
                {
                    
                    stringBuffer.append(color2);
                
                }
                else
                {
                    
                    stringBuffer.append(color3);                    
                    
                }
                
            }
            stringBuffer.append("\n");
            
        }```
#

ive made some progress

#

now i have an extra r sticking out though

#

how do i get them to shift back once?

mossy spruce
#

sorry

#

passed out

#

think of the values that your original loop goes through

#

suppose size is just 5 for simplicity

#

the normal loop will go through 0, 1, 2, 3, 4
so you need to reverse that, 4, 3, 2, 1, 0

#

right now you have 5, 4, 3, 2, 1

mossy spruce
#

@ionic briar