From cb5a703210e00bfb69395b474a276f11c4a918d4 Mon Sep 17 00:00:00 2001 From: Beta-Devin AI <248786709+beta-devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 23 Mar 2026 22:23:59 +0000 Subject: [PATCH] Fix biased shuffle algorithm, broken CSS background-color, and implicit global variables - Fix shuffle(): replace broken implementation with correct Fisher-Yates (Durstenfeld) algorithm. The old version used rand(i) which only selected from indices [0, i-1], producing heavily biased permutations where most orderings were unreachable. - Fix settings modal background-color: add missing '#' prefix to hex color value (000000 -> #000000), introduced in Options panel WIP commit. - Fix implicit global variable 'z' in isStandardSet() and isSuperSet(): add 'var' declaration to for-of loops to prevent global scope pollution. Co-Authored-By: scott.wu46+coggitgrant323@gmail.com --- public/header.js | 6 +++--- public/index.css | 2 +- public/variants.js | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/public/header.js b/public/header.js index faf8aed..4bcf110 100644 --- a/public/header.js +++ b/public/header.js @@ -20,9 +20,9 @@ function rand(x) { } function shuffle(lst) { - for (var i = 0; i < lst.length; ++i) { - var tmp = lst[i] - var j = rand(i); + for (var i = lst.length - 1; i > 0; --i) { + var j = Math.floor(Math.random() * (i + 1)); + var tmp = lst[i]; lst[i] = lst[j]; lst[j] = tmp; } diff --git a/public/index.css b/public/index.css index a9157f4..34eb834 100644 --- a/public/index.css +++ b/public/index.css @@ -254,7 +254,7 @@ svg .stripe.purple { padding: 20px; border: 1px solid #888; width: 80%; /* Could be more or less, depending on screen size */ - background-color: 000000; + background-color: #000000; } /* The Close Button */ diff --git a/public/variants.js b/public/variants.js index 4261157..391b4dd 100644 --- a/public/variants.js +++ b/public/variants.js @@ -20,7 +20,7 @@ function isNotNull(set) { function isStandardSet(set) { if (isNotNull(set) && set.length == 3) { - for (z of ['count', 'color', 'shading', 'shape']) { + for (var z of ['count', 'color', 'shading', 'shape']) { var a = set[0][z], b = set[1][z], c = set[2][z]; if ((a + b + c) % 3 != 0) { return false; @@ -35,7 +35,7 @@ function isSuperSet(set) { if (isNotNull(set) && set.length == 4) { for (var j of [1, 2, 3]) { var cnt = 0; - for (z of ['count', 'color', 'shading', 'shape']) { + for (var z of ['count', 'color', 'shading', 'shape']) { var a = set[0][z], b = set[j][z]; var cd = set[1][z] + set[2][z] + set[3][z] - b; if ((a + b - cd) % 3 != 0) { @@ -220,4 +220,4 @@ Variants = { superset: superset, hiddenset: hiddenset, powerset: powerset -} \ No newline at end of file +}