瀏覽代碼

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