Results 1 to 2 of 2

Math Help - Loop invariants

  1. #1
    Newbie
    Joined
    Jul 2009
    Posts
    3

    Loop invariants

    Consider the following while loop:
    n:=1
    while n<b, do
    print n
    n:=4n-2

    a.) Write the first three numbers printed;
    b.) Find all values of b for which the last number printed will be 342.

    I am at a complete loss as to how to figure this out. I feel like just plugging in 1 for n is far too easy, and if that is the case, it will take far too long to get to 342.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Master Of Puppets
    pickslides's Avatar
    Joined
    Sep 2008
    From
    Melbourne
    Posts
    5,236
    Thanks
    28
    1)
    n:=1
    while n<b, do
    print n
    n:=4n-2

    2)

    n:=4(1)-2 = 2
    while n<b, do
    print n
    n:=4n-2

    3)

    n:=4(2)-2 = 6
    while n<b, do
    print n
    n:=4n-2


    Output will be 1,2,6


    Also

    n : 1, 2, 6, 22, 86

    4n-2: 2, 6, 22, 86, 342
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 0
    Last Post: September 16th 2010, 04:59 AM
  2. For Loop for an m-by-1 matrix
    Posted in the Math Software Forum
    Replies: 20
    Last Post: July 21st 2010, 04:59 PM
  3. Using a for loop and while loop.
    Posted in the Math Software Forum
    Replies: 1
    Last Post: April 19th 2010, 01:18 PM
  4. [SOLVED] Torsion invariants check
    Posted in the Advanced Algebra Forum
    Replies: 0
    Last Post: April 11th 2008, 01:21 AM
  5. Polygon Invariants
    Posted in the Geometry Forum
    Replies: 3
    Last Post: October 13th 2005, 08:45 AM

Search Tags


/mathhelpforum @mathhelpforum