Question

So I am stuck:

I have this algorithm from which I need to find a loop invariant but I just can't get my head around it :

main_f = x
follow_up = x
while (follow_up < y):
   follow_up = follow_up + 1
   main_f = main_f + follow_up

return main_f

So basically I have a list of values of this function(main_f):

Initialisation : i = 0 , main_f = x

Iteration 1: i = 1 , main_f = 2x+1

Iteration 2: i = 2 , main_f = 3x+3

Iteration 3: i = 3 , main_f = 4x+6

Iteration 4: i = 4 , main_f = 5x+10

Iteration 5: i = 5 , main_f = 6x+15

And basically it goes on and on like this in a while (main_f < y) loop;

The loop invariant is certainly a sigma from i=x to y with the "x" part: (i+1)x but i can't find the formula that fits the integer part I got after the iterations.

Thanks in advance for your help

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with cs.stackexchange
scroll top