Преглед на файлове

Change how differential loop ends

Instead of ending when the sum of the array is 0, end when the array
only contains one unique value. It was assumed that if the sum was 0,
then the array only contains zeros, but since it could contain negative
numbers, this assumption was false.
ApisNecros преди 1 година
родител
ревизия
2993698d7e
променени са 1 файла, в които са добавени 2 реда и са изтрити 2 реда
  1. 2 2
      9/9_1.ts

+ 2 - 2
9/9_1.ts

@@ -1,4 +1,4 @@
-import { ExtractNumbers, Inspect, LoadInput } from "../common.ts";
+import { ArrayIsOnlyDuplicates, ExtractNumbers, Inspect, LoadInput } from "../common.ts";
 
 const tests = [
     "0 3 6 9 12 15",
@@ -39,7 +39,7 @@ function PredictNextValue(histogram: number[]): number[] {
     do {
         differential = FindDifferential(allDifferentials[0]);
         allDifferentials.unshift(differential);
-    } while (SumArray(differential) != 0);
+    } while (!ArrayIsOnlyDuplicates(differential));
 
     while (allDifferentials.length > 1) {
         // Store the last value of previous differential, and remove that differential from the list