20x20 그리드에서 어떤 방향으로도 인접한 숫자의 최대 값은 무엇입니까 (위, 아래, 왼쪽, 오른쪽 또는 대각선)입니까?프로젝트 오일러 # 11 : 파이썬 솔루션이 작동하지 않습니다.
http://projecteuler.net/problem=11
나는 숫자 두 차원 튜플, 목록을 만들었습니다.
LIST = ((8, 2, 22, ...), (49, 49, 99, ...) ...)
여기에 내 용액이다. 나는 논리적 인 결함을 알아낼 수 없다.
(편집) : 내 답변은 51267216이지만 올바르지 않습니다.
# For every number check diagnolly, down and right if the product exceeds max_product.
# Ignore the exception(OutOfBounds) if encountered.
max_product = 0
for i in range(20):
for j in range(20):
temp = 1
try:
for k in range(4):
temp = temp * LIST[i][j+k]
if (temp > max_product):
max_product = temp
except:
pass
temp = 1
try:
for k in range(4):
temp = temp * LIST[i+k][j]
if (temp > max_product):
max_product = temp
except:
pass
temp = 1
try:
for k in range(4):
temp = temp * LIST[i+k][j+k]
if (temp > max_product):
max_product = temp
except:
pass
print max_product
왜 작동하지 않습니까? 코드에서 부품을 지적하십시오. 출력은 무엇입니까? 예상 * 결과는 무엇입니까? – Tim
@tim : Project euler는 최대 제품을 찾고 있습니다. 찾으면 상자에 넣고 확인하십시오. 내 출력은 51267216이지만 올바르지 않습니다. – Shubham
더 구체적인 질문이나 문제가 없으면 http://codereview.stackexchange.com/ – stderr