From fd448390652ade6c12aa0c1211a08e045e0737e3 Mon Sep 17 00:00:00 2001 From: Olivia Appleton Date: Thu, 8 Aug 2024 23:54:07 -0500 Subject: [PATCH] Correct width of array --- cplusplus/src/p0016.cpp | 2 +- csharp/Euler/p0016.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cplusplus/src/p0016.cpp b/cplusplus/src/p0016.cpp index 60c3bc52..e23bbcf8 100644 --- a/cplusplus/src/p0016.cpp +++ b/cplusplus/src/p0016.cpp @@ -14,7 +14,7 @@ What is the sum of the digits of the number 2**1000? unsigned long long p0016() { - std::vector numbers(16, 0); + std::vector numbers(18, 0); const unsigned long long ten17 = 100000000000000000; numbers[0] = 1; for (unsigned short i = 0; i < 1000; i++) { diff --git a/csharp/Euler/p0016.cs b/csharp/Euler/p0016.cs index 9ad38174..30ecfc49 100644 --- a/csharp/Euler/p0016.cs +++ b/csharp/Euler/p0016.cs @@ -15,16 +15,16 @@ public class p0016 : IEuler { public object Answer() { - ulong[] numbers = new ulong[16]; + ulong[] numbers = new ulong[18]; const ulong ten17 = 100000000000000000; numbers[0] = 1; for (ushort i = 0; i < 1000; i++) { - for (byte j = 0; j < 16; j++) + for (byte j = 0; j < 18; j++) { numbers[j] *= 2; } - for (byte j = 0; j < 15; j++) + for (byte j = 0; j < 17; j++) { if (numbers[j] > ten17) { @@ -37,7 +37,7 @@ public object Answer() ulong power = 1; for (byte i = 0; i < 19; i++) { - for (byte j = 0; j < 16; j++) + for (byte j = 0; j < 18; j++) { ulong value = numbers[j] / power; answer += value % 10;