Alexander Alexeev avatar Alexander Alexeev committed b549ff4

not_visited_cells_list function refactoring

Comments (0)

Files changed (1)

 (* Генерируем список с координатами всех ячеек
    в лабиринте заданного размера *)
 let not_visited_cells_list width height =
-  let max_x = width - 1
-  and max_y = height - 1 in
-    let rec not_visited_cells_list' x y acc =
-      if x == 0
-      then if y == 0
-           then (0,0) :: acc
-           else not_visited_cells_list' max_x (y-1) ( (0,y) :: acc )
-      else not_visited_cells_list' (x-1) y ( (x,y) :: acc )
-    in
-      not_visited_cells_list' max_x max_y []
+  let lst = ref [] in
+  for y = height-1 downto 0 do
+    for x = width-1 downto 0 do
+      lst := (x,y) :: !lst
+    done
+  done;
+  !lst
 
 (* Верно ли, что заданная ячейка не соединена
    ни с одной другой? *)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.