Jelajahi Sumber

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 tahun lalu
induk
melakukan
2993698d7e
1 mengubah file dengan 2 tambahan dan 2 penghapusan
  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 = [
 const tests = [
     "0 3 6 9 12 15",
     "0 3 6 9 12 15",
@@ -39,7 +39,7 @@ function PredictNextValue(histogram: number[]): number[] {
     do {
     do {
         differential = FindDifferential(allDifferentials[0]);
         differential = FindDifferential(allDifferentials[0]);
         allDifferentials.unshift(differential);
         allDifferentials.unshift(differential);
-    } while (SumArray(differential) != 0);
+    } while (!ArrayIsOnlyDuplicates(differential));
 
 
     while (allDifferentials.length > 1) {
     while (allDifferentials.length > 1) {
         // Store the last value of previous differential, and remove that differential from the list
         // Store the last value of previous differential, and remove that differential from the list