]> git.ardis.lu - seed-phrase-transposer/commitdiff
Show more likely permutations first
authorArdis Lu <ardisglu@gmail.com>
Fri, 10 Jan 2025 06:45:30 +0000 (22:45 -0800)
committerArdis Lu <ardisglu@gmail.com>
Fri, 10 Jan 2025 06:45:30 +0000 (22:45 -0800)
Grids are more likely to be presented in a "balanced" way (e.g., a 3x4 grid is more likely than 2x6 grid). So showing "balanced" permutations first may reduce manual test time.

README.md
main.ts
main_test.ts

index cec4ba144eb746100e3c89fe1b62a00a09d15b4a..1218d77260d1505985a43d2cbd070ff9ca1f22ef 100644 (file)
--- a/README.md
+++ b/README.md
@@ -43,10 +43,10 @@ correct one:
 > deno run main.ts
 Seed phrase: 1 4 7 10 2 5 8 11 3 6 9 12
 
-1 8 4 11 7 3 10 6 2 9 5 12
-1 7 2 8 3 9 4 10 5 11 6 12
 1 2 3 4 5 6 7 8 9 10 11 12 <-- Correct permutation found!
 1 10 8 6 4 2 11 9 7 5 3 12
+1 8 4 11 7 3 10 6 2 9 5 12
+1 7 2 8 3 9 4 10 5 11 6 12
 ```
 
 ## Usage
diff --git a/main.ts b/main.ts
index 831eb61586762e7eabb0a3ec50b4eaa9b3d44ef3..3ad22d113c9a281e20bc6800c7a1b6f2a2d6cb9f 100644 (file)
--- a/main.ts
+++ b/main.ts
@@ -60,6 +60,7 @@ export function getLowerFactors(num: number): Array<number> {
       lowerFactors.push(i);
     }
   }
+  lowerFactors.reverse(); // The middle factors are the most likely grid arrangements, test those first
   return lowerFactors;
 }
 
index 819cbf328fa9ceacd3e7afa9edec112abde695ad..5531c84a135367b402cacb094347d1e888b4e2ce 100644 (file)
@@ -1,5 +1,6 @@
 import { getLowerFactors, getPermutations, main, parseInput } from "./main.ts";
 import {
+  assert,
   assertArrayIncludes,
   assertEquals,
   assertFalse,
@@ -193,6 +194,13 @@ Deno.test("getLowerFactors returns correct factors of 24", () => {
   assertFalse(factors.includes(12));
 });
 
+Deno.test("getLowerFactors returns an array sorted high-to-low", () => {
+  const factors = getLowerFactors(24);
+  for (let i = 0; i < factors.length - 1; i++) {
+    assert(factors[i] > factors[i + 1]);
+  }
+});
+
 Deno.test("main logs permutations of a 12-word seed phrase", () => {
   using consoleSpy = spy(console, "log");
   using _promptStub = stub(
This page took 0.049499 seconds and 4 git commands to generate.