2017년 6월 18일 일요일

Loop wthin a loop only integrating once- think I have it in the wrong place?


I'm working on an app that creates a triangle using text.  The app can either create a right angle triangle from astericks, or an isosceles triangle that is inverted and NOT a right angle.

The user inputs the length of a/the triangle side.

I'm getting everything to function, except the space used to center the triangle only iterates once, stumped on why my placement is incorrect.  Including screen shots and aia.





--
To get indentation of the triangle,  you have to change the JOIN used to add a '*'.
Add an extra layer to the inner JOIN, to make a 3 layer sandwich:
  a blank,
  the variable,
 a star.

By the way, you can rename the loop variable, for clarity's sake.

-- 
Are we talking three layers like a sandwich, or three layers all inside each other, like a turducken? ;)

-- 
Tried this out and it places all the spaces at the front of the triangle....

Clearly I need more than two hours of sleep and half a cup of coffee.....



-- 
Oops, sorry - I gave you bad advice.

My advice would cause the triangle to skew.

For an isosceles triangle you would need the indentation to increase as the width of the triangle decreases.

The width of the triangle would need to change at twice the rate of the indentation, otherwise it would be a right triangle.

You can verify this with a piece of graph paper.

There is a handy segment block in the text blocks that can be used with a long string of blanks or stars to create arbitrarily long strings of blanks or stars,
to eliminate the need for nested loops.

Given that, all you need is a pair of formulas for the number of blanks (for indentation) and stars 
based on the height up (or down) the triangle of that row.
The formulas should be linear.

-- 

댓글 없음:

댓글 쓰기