# [Tutor] python programmin problem

monikajg at netzero.net monikajg at netzero.net
Wed Jul 20 19:14:49 EDT 2016

```IM not able to figure out algorithm to find the runs.
Here is the code I have:

def ProgressCalc(items):
counts = [items[0]]
for i in range(1, len(items)-1):
print "for loop", items[i], items[i + 1]
if counts[- 1] < items[i]:
counts += [items[i]]
print "inside", items[i], items[i - 1], counts

print counts

counts = [items[0]]
for i in range(1, len(items) - 1):
print "for loop", items[i], items[i + 1]
if counts[- 1] <= items[i] and items[i] < items[i + 1]:
counts += [items[i]]
print "inside", items[i], items[i - 1], counts
elif counts[- 1] <= items[i] and items[i] > items[i + 1]:
counts += [items[i]]
i += 2
print counts
ProgressCalc(items)

---------- Original Message ----------
From: Alan Gauld <alan.gauld at yahoo.co.uk>
To: "monikajg at netzero.net" <monikajg at netzero.net>
Cc: tutor at python.org
Subject: Re: python programmin problem
Date: Thu, 21 Jul 2016 00:11:24 +0100

On 20/07/16 22:11, monikajg at netzero.net wrote:
> ... if not in python, then in pseudo code.

The first question to ask is can you do it without a computer?
In other words given

input [1,7,2,3,5,4,6]

Can you first of all produce a list of all valid runs?

[1,2,3,5,6] and [1,2,3,4,6] both have length 5

I also see shorter runs:

[7] and [4,6] for example.

Can you manually create a list of all valid runs?

Once you can do that can you write a program to
generate that as a list of lists in Python?

If so then the answer to your question is a matter of
finding the length of the longest valid run which
should be fairly easy.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos

____________________________________________________________
Affordable Wireless Plans
Set up is easy. Get online in minutes.
Starting at only \$9.95 per month!
www.netzero.net?refcd=nzmem0216
```