[Tutor] Re: you may regret that comment Magnus!!

Magnus Lycka magnus@thinkware.se
Thu Jan 30 21:40:02 2003


Hi, it seems your mail didn't reach the mailing list.
I don't know if the Word attachment caused rejection,
or if the subject line triggered some flame-war
filter! ;)

Anyway, maybe it would be better if you could put the
image on some web location, and just post a URL with
your mail.

Obviously, this algorithm is written in an unstructured
way, completely violating everything Dijkstra and others
have said, so it would be easier to code without a lot
of thinking in a language that supported GOTO, such as
BASIC or C.

I don't think it's a big issue though. The problem is
that the flow chart is not a description of the problem,
it's a suggested solution, and a solution made up with an
idea that the tool will look different from the one we use:
Python.

The same basic algorithm could be described differently
(well, much smarter) and then be much easier to find a
structured solution for.

For instance, loops with j = j + 1 just before j > jM,
and i = i + 1 just before i > nsp are simply for loops
in disguise. Also, the needlessly crossing path makes it
more difficult to see the structured solution.

These kinds of problems are fairly common. We'll have to
twist it a bit. Personally I'd just look at the flow chart
and code.

I have some trouble distinguishing between 1 (one) and
l (ell) in the picture. Could you clarify that?

Roughly, your structure should be

#init things

for j in range(2, jM+1):
     x = rnd()
     if x < ...:
         abund.append(1)
     else:
         cum[l or 1?] = ...
         for i in range(l+1 or 2?, nsp+1):
             cum[i] = ...
         i = 1 or l???
         while x >= cum[i]:
             i += 1
         abund[i] += 1 ?

Also, nsp could be a function, instead of a variable etc.

At 14:37 2003-01-30 -0800, Mic Forster wrote:
>--- Magnus Lycka <magnus@thinkware.se> wrote:
> > If you tell us what you want to achieve, we'll tell
> > *you* what you need to create! ;)
> >
>
>
>I wasn't going to burden anyone with this but, well,
>Magnus I just couldn't turn down your offer. Attached
>is an algorithm I want to convert into Python. Any
>advice?
>
>Cheers,
>Mic Forster

-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se