Stuck in a loop

Discussion in 'Python' started by hexusnexus@gmail.com, Apr 1, 2008.

  1. Guest

    I wrote a simple algorithm and it keeps getting stuck in a loop. I
    guess I'm just to tired to figure it out:

    compcount=[5,4,2,2]
    suitrank=[0,0,0,0]

    trump=2
    l,lt=0,0
    while l<4:
    while lt<4:
    if l==trump:
    l+=1
    if l>3:
    break
    if lt==trump:
    lt+=1
    if compcount[l]<compcount[lt]:
    suitrank[l]+=1
    lt+=1
    l+=1

    In case you're wondering, the point is to rank suits from highest to
    lowest based on how few cards each suit has. I hope that's enough
    information.
     
    , Apr 1, 2008
    #1
    1. Advertising

  2. Dan Bishop Guest

    On Mar 31, 8:22 pm, wrote:
    > I wrote a simple algorithm and it keeps getting stuck in a loop. I
    > guess I'm just to tired to figure it out:
    >
    > compcount=[5,4,2,2]
    > suitrank=[0,0,0,0]
    >
    > trump=2
    > l,lt=0,0
    > while l<4:
    > while lt<4:
    > if l==trump:
    > l+=1
    > if l>3:
    > break
    > if lt==trump:
    > lt+=1
    > if compcount[l]<compcount[lt]:
    > suitrank[l]+=1
    > lt+=1
    > l+=1
    >
    > In case you're wondering, the point is to rank suits from highest to
    > lowest based on how few cards each suit has. I hope that's enough
    > information.


    Inside the inner loop, lt never changes if lt != trump, so you get an
    infinite loop the first time when lt == 0.

    I think you may have misindented the last two lines.
     
    Dan Bishop, Apr 1, 2008
    #2
    1. Advertising

  3. Terry Reedy Guest

    <> wrote in message
    news:...
    |I wrote a simple algorithm and it keeps getting stuck in a loop. I
    | guess I'm just to tired to figure it out:

    The easiest way to figure out somethinglike this is to print your variables
    from inside the loop to see things stick, or if there is a cycle.

    | compcount=[5,4,2,2]
    | suitrank=[0,0,0,0]
    |
    | trump=2
    | l,lt=0,0
    | while l<4:
    | while lt<4:

    print l, lt

    | if l==trump:
    | l+=1
    | if l>3:
    | break
    | if lt==trump:
    | lt+=1
    | if compcount[l]<compcount[lt]:
    | suitrank[l]+=1
    | lt+=1
    | l+=1
     
    Terry Reedy, Apr 1, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RGFuIFNpa29yc2t5?=

    HttpModule Error Handler Stuck In Loop

    =?Utf-8?B?RGFuIFNpa29yc2t5?=, Jul 18, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    562
    =?Utf-8?B?RGFuIFNpa29yc2t5?=
    Jul 19, 2006
  2. =?Utf-8?B?SWFu?=
    Replies:
    1
    Views:
    498
    RobinS
    Feb 13, 2007
  3. Steve Edwards
    Replies:
    8
    Views:
    1,126
  4. James

    stuck in Infinite-loop

    James, Nov 13, 2009, in forum: C Programming
    Replies:
    24
    Views:
    787
    Barry Schwarz
    Nov 18, 2009
  5. Isaac Won
    Replies:
    9
    Views:
    420
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page