On 20/08/2012 21:24, Osemeka Osuagwu wrote:
Dear Pythonistas (I hope you don't mind that),
I wrote the following code to find the four adjacent numbers (in any
direction in the array) which, when multiplied together, would yield the
I can't see a Python array anywhere. Do you mean the list of lists? :)
highest product to be gotten. I finally stumbled on the answer while
studying the data itself but I'm still stumped as to why I keep getting an
error while running the code. I would like answers to this and also any
suggestions as to more elegant ways of solving this problem.
THE CODE
[snipped as it's been mangled, was it posted in html and not plain text
or what? I'm too lazy to unmangle it, others might be kinder]
THE ERROR
Traceback (most recent call last):
File "C:\Windows.old\Users\Abasiemeka\Abasiemeka\GOOGLE
University\Python\Python Code\MyCode\Project Euler code\Project Euler
answer 11.py", line 84, in <module>
main()
File "C:\Windows.old\Users\Abasiemeka\Abasiemeka\GOOGLE
University\Python\Python Code\MyCode\Project Euler code\Project Euler
answer 11.py", line 64, in main
if right_product(row, col) > prod:
File "C:\Windows.old\Users\Abasiemeka\Abasiemeka\GOOGLE
University\Python\Python Code\MyCode\Project Euler code\Project Euler
answer 11.py", line 49, in right_product
return reduce(lambda x,y:x*y, [data[row][i] for i in range(col, col+4)])
IndexError: list index out of range
p.s I apologise for the lack of comments
Regards,
Abasiemeka
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
The usual way to chase a problem like this is to place print statements
in appropriate places in your code. The for loops in your main function
look like a good starting point to me. Please try that and see what you
come up with.
--
Cheers.
Mark Lawrence.
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor