I need a help making version of a for i block

My idea is to have any number (lets say 20), and make a for i block that, when all the numbers in the for i are added, equal the number (20). So if I set the number to 55, the for i block should do “for i 1-10” because 1+2+3+… +10 = 55.

I want to be able to input any number and have the for i block get it right each time, but I have no idea what the math for that would even be.

The nth triangle number is n(n+1)/2. So if you’re given a number t and you want to find the smallest number n whose triangle number is \ge t, you get n^2 + n -2t = 0. Solve for n with the quadratic formula:


and then use

or, better yet, do it functionally by using
untitled script pic (8)
For example,

Or use FLOOR instead of CEILING if that’s what you want.

If you want a more streamlined approach that doesn’t involve much math, you can do this.


idk what to call it, so I just used untriangle from bh’s script

I started with the base definition of the primitive block (by right clicking it and clicking “edit” to see the definition), then tweaked it to make the value that’s checked is the total sum instead of the count.

Thanks so much!