Przeglądaj źródła

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 rok temu
rodzic
commit
2993698d7e
1 zmienionych plików z 2 dodań i 2 usunięć
  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