Simple O(1) C++ solution


#1

int Solution::solve(int A, int B) {
int sum = 0;
sum += min(8-A, 8-B);
sum += min(B-1, 8-A);
sum += min(A-1, 8-B);
sum += min(B-1, A-1);
return sum;
}