Python Beginner tutorial series using project Euler #11 - Largest product in a grid

preview_player
Показать описание
Not as nice as I'd like it to be, having to copy in the grid isn't nice but it works and is significantly easier than other methods I can think of. Hopefully this helps some of you :)

Please don't forget to like if you liked the video and subscribe if you want to see more, thanks!

Рекомендации по теме
Комментарии
Автор

For anyone wanting to implement the same array in python, try pasting it in a text editor, replace all spaces (" ") with a space and a comma (", "), and all new lines ("/n") with a closing bracket, a new line, and an opening bracket ("]/n[").
That way you can just copy/paste the entire thing into yuur code and use it :)

Vancha
Автор

For anyone who wants to import the grid, I did it this way:

#saved the grid in a .txt file, and use a context manager (best practice)
with open("problem11/input.txt", "r") as f:
x = f.read().splitlines()

def parse(x):
#returns a list of lists
newlist = []
for i, strings in enumerate(x):
strings = strings.split()
#create a new list in our list
newlist.append([])
for j in strings:
newlist[i].append(int(j))
return newlist

samdurden
Автор

Instead of using 4 different for loops. You could directly run try and except and complete the entire process in the first two loops of "i" and "j" themselves. Anyways, thanks a lot bro.

ishaanadarsh
Автор

Thanks a lot Luke. However, I would have used numpy.transpose to get the values for the downward/upward directions and deleted the code in the middle :)

mortenvonsildskjde
join shbcf.ru