r/ProgrammerHumor • • Aug 26 '20

Python goes brrrr

Post image
59.2k Upvotes

789 comments sorted by

View all comments

Show parent comments

3

u/juzz_fuzz Aug 26 '20

I kind of think I understand so you initialized a list, trying to go from 0 to negative, using another list, so that list would be reversed, but the code never checks if the list is empty first? am I close?

3

u/IMayBeABitShy Aug 26 '20

Sorry, I mistyped and had the : in the wrong position. The actual bug is in the spoiler tag of the original comment. Basically, if you are referencing x[-y], you have to check for y to not be 0, otherwise the first element will be used instead of the last one.

2

u/juzz_fuzz Aug 26 '20

that is true, but based on the https://projecteuler.net/problem=11 problem I was working on, that simply didn't matter as you would always be using 4 adjacent values, so going 1,0,-1,-2 is dandy