[Tutor] Re: rotating a list
Bob Gailer
bgailer at alum.rpi.edu
Sat Sep 20 22:00:08 EDT 2003
At 02:33 PM 9/20/2003, Andrei wrote:
>Bob Gailer wrote:
>>>Here's your problem your rotate x and assign the result to y:
>>>
>>>> y = rotate(x)
>>>
>>>
>>>Now x is unchanged, y is the result, so you go back and rotate the same
>>>old x again. Obviously the result won't change.
>>>
>>>> print y
>>
>>No that is NOT the problem. That is an alternative algorithm. I explained
>>the problem in my post.
>
>As far as I can tell, that's a matter of taste: the algorithm is exactly
>the same and the result is the same: he uses the default value of n=1 in
>this case to test his rotation which is just fine. One can either
>increment n in the loop or reassign x every time. Personally, I find
>reassigning more intuitive and I pretty much ignored the optional n
>parameter. Could you explain why incrementing n is a superior solution?
I guess I overreacted in my reply. I did see what you saw first, then when
I tested the code and saw the missing parameter I assumed the OP meant to
provide it. Sorry for the reaction.
As a (mostly former) APL programmer I still like APL's approach best:
n$matrix
where $ is replaced by the non-ascii symbol for rotate.
Bob Gailer
bgailer at alum.rpi.edu
303 442 2625
-------------- next part --------------
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003
More information about the Tutor
mailing list