我在项目euler网站上遇到了问题,而我却陷入了第二个问题.
这是问题所在:
Fibonacci序列中的每个新术语都是通过添加前两个术语生成的.从1和2开始,前10个术语将是:
Run Code Online (Sandbox Code Playgroud)1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...通过考虑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)
我不确定什么行不通.有帮助吗?
这是我的代码:
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)