From: Ardis Lu Date: Fri, 10 Jan 2025 06:45:30 +0000 (-0800) Subject: Show more likely permutations first X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=66a6e32f7df08f85f6fd46d742a9956bbc34fbff;p=seed-phrase-transposer Show more likely permutations first 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. --- diff --git a/README.md b/README.md index cec4ba1..1218d77 100644 --- 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 831eb61..3ad22d1 100644 --- a/main.ts +++ b/main.ts @@ -60,6 +60,7 @@ export function getLowerFactors(num: number): Array { lowerFactors.push(i); } } + lowerFactors.reverse(); // The middle factors are the most likely grid arrangements, test those first return lowerFactors; } diff --git a/main_test.ts b/main_test.ts index 819cbf3..5531c84 100644 --- a/main_test.ts +++ b/main_test.ts @@ -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(