SE250:lab-X:gfun006

From Marks Wiki
Jump to navigation Jump to search

Task 1

There are 9 possible spaces to put in "1 2 3 4 5 6 7 8 X" where X is the empty space. Thus in the first space there are 9 different possibilities, then 8, then 7 etc, ending up with 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = 9! = 362880. The number of edges is I estimated was (4 x 8! + 3x4 x 8! + 2x4 x 8!)/2. That is a pure estimate, but I got that answer because I figured that when the state has a empty space in the middle, there are 4 different ways to move, when they are on the corners, there are 2 different ways and on the sides there are 3 different ways. There can only be one instance when the empty space is in the middle, 4 instances for the corner and 4 for the sides. Also, there is always the possibility of a state returning backwards, thus the answer is divided by 2.

Task 2

STACK

Task 3

               1 2 3
               4 5 6   
                 7 8
 
      1 2 3              1 2 3
        5 6              4 5 6
      4 7 8              7   8

1 2 3        2 3   1 2 3       1 2 3
5   6      1 5 6   4   6       4 5 6
4 7 8      4 7 8   7 5 8       7 8

There is always also the possibility of making a move back to the parent state every time. Spent a lot of time figuring out how cygwin works and then had to change the dot command again. It was not fun.

Task 4

For some reason my search.c kept printing 10714 nodes. I don't know why.

Oh right, I'm an idiot and forgot to change the start and goal. I changed start to "123456.78" and goal to "12345678.". This gave me the output of: <HTML>

123
456
.78


123
456
7.8


123
456
78.
123
456
.78
 ->
123
456
7.8
 ->
123
456
78.
 ->
Visited 5 states

</HTML>

I put the print_state(&s) command after the pop_OrderedStateList( &open, &s ) command. The output seems to make sense...although I don't understand why it visited 5 states. It seemed to only go through 3.