瀏覽代碼

Update 15-puzzle.md (#345)

Implements the Fisher-Yates algorithm to produce unbiased permutations.
Lázaro Albuquerque 2 年之前
父節點
當前提交
ebf3f83e48
共有 1 個文件被更改,包括 3 次插入2 次删除
  1. 3 2
      docs/en/tutorials/15-puzzle.md

+ 3 - 2
docs/en/tutorials/15-puzzle.md

@@ -112,8 +112,9 @@ end
 
 -- Randomize the order of a the elements in a table list
 local function scramble(t)
-    for i=1, #t do
-        t = swap(t, i, math.random(#t))
+    local n = #t
+    for i = 1, n - 1 do
+        t = swap(t, i, math.random(i, n))
     end
     return t
 end