Dec-05-2017, 04:35 AM
#--Horizonal for i in range(len(pList)-3): prod = 1 for x in range(4): prod *= int(pList[i+x]) prods.append(prod) #--Vertical for i in range(114): prod = int(pList[i]) step = 0 thelist = str(prod) + "," for x in range(3): step += i + 20 thelist += str(pList[step]) + "," prod *= int(pList[step]) prods.append(prod)So I have a 20x20 grid of numbers (it's actually just a list of numbers, and I'm parsing it like it's 20x20. I am able to get the horizonal and vertical products of every set of 4 numbers, but I can't quite wrap my head around getting the diagonal ones. I tried altering the code for vertical and just changing the 20 to 21, which does the job, but it also wraps around the grid (it grabs an item on position 17-20 of each line and goes diagonal, only to wrap into the next line, when it shouldn't grab anything at all passed element 16 of each line). Also, it doesn't grab the reverse.
I've looked online, can't really find anything that suits my needs to learn from. Any pointers here?
Thanks