-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
36 lines (31 loc) · 999 Bytes
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from random import shuffle
from CS3243_P1_01_1 import Puzzle, Node
from time import time
def test():
dimension = eval(input("Enter dimension:"))
n = eval(input("Enter number of times:"))
goal_state = convert_list_to_2d(dimension, [e for e in range(1, dimension*dimension)] + [0])
print(goal_state)
for i in range(n):
start = time()
curr = generate_puzzle(dimension)
print(curr)
puzzle = Puzzle(curr, goal_state)
ans = puzzle.solve()
end = time()
print(ans)
print(end - start)
# print_2d_lst(generate_puzzle(5))
return
def generate_puzzle(dimension):
lst = [e for e in range(dimension*dimension)]
shuffle(lst)
return convert_list_to_2d(dimension, lst)
def convert_list_to_2d(dimension, lst):
res = []
for i in range(0, len(lst), dimension):
res.append(lst[i:i+dimension])
return res
def print_2d_lst(two_d_lst):
print('\n'.join(str(lst) for lst in two_d_lst))
test()