|
|
@ -74,19 +74,10 @@ let change_seats is_far l =
|
|
|
|
)
|
|
|
|
)
|
|
|
|
) l
|
|
|
|
) l
|
|
|
|
|
|
|
|
|
|
|
|
let hash = Hashtbl.create 1000
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let grid_equal g1 g2 = (* abusing hash but not a drug problem *)
|
|
|
|
|
|
|
|
match Hashtbl.find_opt hash g2 with
|
|
|
|
|
|
|
|
| Some _ -> true
|
|
|
|
|
|
|
|
| None ->
|
|
|
|
|
|
|
|
let _ = Hashtbl.add hash g2 0 in
|
|
|
|
|
|
|
|
false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let rec start is_far grid = (* keep changing seats until the grid stops changing *)
|
|
|
|
let rec start is_far grid = (* keep changing seats until the grid stops changing *)
|
|
|
|
(* print_grid grid; *)
|
|
|
|
(* print_grid grid; *)
|
|
|
|
let grid' = change_seats is_far grid in
|
|
|
|
let grid' = change_seats is_far grid in
|
|
|
|
if grid_equal grid grid'
|
|
|
|
if grid = grid'
|
|
|
|
then grid'
|
|
|
|
then grid'
|
|
|
|
else start is_far grid'
|
|
|
|
else start is_far grid'
|
|
|
|
|
|
|
|
|
|
|
|