小编use*_*556的帖子

项目欧拉#2

我在项目euler网站上遇到了问题,而我却陷入了第二个问题.

这是问题所在:

Fibonacci序列中的每个新术语都是通过添加前两个术语生成的.从1和2开始,前10个术语将是:

 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
Run Code Online (Sandbox Code Playgroud)

通过考虑Fibonacci序列中的值不超过四百万的项,找到偶数项的总和.

这是我的代码:

a = 0
b = 0
c = 2
d = []
x = 1
y = 2
z = [1,2]
while x + y <= 4000000:
    z.append(x+y)
    x = y
    y = z[c]
    c += 1

size = len(z)
while a < (size - 1):
    if z[a] % 2 == 0:
        d.append(z[a])
    a += 1

print(sum(d))
Run Code Online (Sandbox Code Playgroud)

我不确定什么行不通.有帮助吗?

python

3
推荐指数
1
解决办法
1612
查看次数

"即使我没有使用任何整数,也不能隐式地将类型'float'转换为'int'

这是我的代码:

float SmoothNoise(float x, float y)
{
    float fractX = x - (int)x;
    float fractY = y - (int)y;

    float x1 = ((int)x + noiseWidth) % noiseWidth;
    float y1 = ((int)y + noiseHeight) % noiseHeight;

    float x2 = ((int)x + noiseWidth - 1f) % noiseWidth;
    float y2 = ((int)y + noiseHeight - 1f) % noiseHeight;

    float value = 0f;

    value += fractX * fractY * noise[x1, y1];
    value += fractX * (1f - fractY) * noise[x1, y2];
    value += (1f …
Run Code Online (Sandbox Code Playgroud)

.net c# arrays

-3
推荐指数
1
解决办法
761
查看次数

标签 统计

.net ×1

arrays ×1

c# ×1

python ×1