- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
What is the greatest product of four adjacent numbers in any direction (up, down, left, right, or diagonally) in the 20×20 grid?
http://projecteuler.net/problem=11
我从数字创建了二维元组 LIST。
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
最佳答案
您是否忘记了有两个对角线方向?
关于python - 欧拉计划 #11 : Python solution not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9014001/
在编程中,我只使用整数。不过这次要进行一些计算。我需要计算Euler-Mascheroni Constant γ .最多 n 位小数。{虽然 n ∈ [30, 150]对我来说已经足够了。 [x] =
有人可以帮忙处理这段代码吗?它应该得到第 10,001 个素数。我知道 is_prime 函数可以测试一个数字是否为素数,因为我成功地利用此代码解决了上一个问题。现在我只是尝试在 for 循环中调用它
我发现了几个与这个问题相关的主题,我只是想知道为什么我的代码返回不正确的数据。所以我们必须找到第一个除数超过 500 的三角形数。详情可在此处找到:http://projecteuler.net/pr
#include int main(void) { char *num = "73167176531330624919225119674426574742355349194934"
我正在尝试投影欧拉问题 8,但是我遇到了问题。1000位数字中相邻四位的乘积最大为9×9×8×9=5832。 731671765313306249192251196744265747423553491
这是针对 Project Euler 19 的。我几乎想出了代码,但由于某种原因我的输出是 +1。 #include #define SIZE 12 int main(void) {
int main(void) { int n, div, a, b; double phi; printf("Enter n:\n"); if (scanf("%d", &n) < 1
欧拉问题: 如果我们列出所有 10 以下的自然数,它们是 3 或 5 的倍数,我们得到 3、5、6 和 9。这些倍数的和是 23。 求 1000 以下的所有 3 或 5 的倍数之和。 我试图从 pro
我知道这可能会被否决,但我真的很沮丧 24 小时,查看其他 Euler 3 线程并没有帮助我解决这个问题。有人可以帮助我的代码吗?我认为我非常接近。 function is_prime(num) {
我卡在了Question 7欧拉计划。我有这段代码。 #include int main (void) { int contador = 0, i, n, variavel = 0;
我正在尝试使用 sympy 的 idiff 函数对某些表达式执行隐式微分。 在本例中,rdot 为 dr/ds,其中 s 是仿射参数。我想对相同的仿射参数对 Ltdot、Lphidot 和 Lrdot
我正在尝试解决我的第一个项目 Euler 问题,只是为了玩 Rust,但被困在似乎需要极长计算时间的问题上 问题: https://projecteuler.net/problem=757 我想出了这
我正在学习C编程,并制定了以下算法来解决这个问题: 代码实际上有效,但最初循环只有 10 次重复(rep int main() { float p; //the power for e
我之前曾尝试暴力破解它,但没有成功。这是我的递归尝试#2(第一次使用递归方法)。请帮忙! 发生的情况是这样的:代码运行良好,数字较小,但是当我们达到一百万时,代码就会运行,并且什么也不会发生。在 Ec
Given a number find the 5 digits before the trailing 0. 9! = 362880 so f(9)=36288 10! = 3628800 so f
我是一名优秀的程序员,十分优秀!