Why different output?
I tried to resolve this problem and I can't with javascript only using python, what is wrong is '%' different in javascript?
I use '%' to get last 10 digits from the result.
Javascript:
const puzzle = (N, P) => {
var A = 1,
B = 1,
C = 1,
D = 1,
X;
for (var j = 0; j < P; j++)
for (var i = 0; i < N; i++) {
X = D + 2 * C + 3 * B + 4 * A;
A = B;
B = C;
C = D;
D = X;
}
return D % 10000000000;
};
console.log(puzzle(10, 1));
console.log(puzzle(100, 1));
console.log(puzzle(2022, 100));
Python:
def puzzle(N, P):
A = 1;
B = 1;
C = 1;
D = 1;
X = 0;
for ea in range(P):
for esa in range(N):
X = D + 2 * C + 3 * B + 4 * A;
A = B;
B = C;
C = D;
D = X;
return D % 10000000000;
print(puzzle(10, 1));
print(puzzle(100, 1));
print(puzzle(2022, 100));
Output (Python):
> 30520
> 720820623
> 5553751141