Преглед на файлове

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