unable to solve http://www.codechef.com/problems/H1

please someone help me in doing http://www.codechef.com/problems/H1 . I need help with the logic of this problem. Is there any editorial related to this?

Doing a bfs on the states of the board, mapping each state of the board to the distance from the root(minimum number of moves required from the original board) should solve it.

Pseudo code:-
function bfs()
{
queue<board> Q;
map<board, int> dist;
Q.push(original board);
dist[original board] = 0;
while(!Q.empty())
{
board t = Q.front(); Q.pop(); 
d = dist[t];
if (issorted(t)){return d;}
for all boards i which can be obtained from t using 1 swap
{
  if (dist.count(i)==0){Q.push(i); dist[i] = d+1;}
}}return -1;}

I will implement it and post the link when I get some time!