Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void main() {
- List<int> board = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
- isSolvable(board) ? print("Solvable") : print("Not Solvable");
- }
- int getInvCount(List<int> arr){
- int inv_count = 0;
- int N = arr.length;
- for(int i = 0; i < N -1; i++){
- for (int j = i +(i * 4) + 1; j < N; j++){
- if (arr[j] && arr[i] && arr[i] > arr[j])
- inv_count++;
- }
- }
- return inv_count;
- }
- int findXPosition(List<int> arr) {
- int N = arr.length;
- for(int i = N-1; i >= 0; i--)
- for(int j = N-1; j>=0; j--)
- if(arr[i+(j * 4)] == 0)
- return N - i;
- }
- bool isSolvable(List<int> puzzle){
- int N = puzzle.length;
- int inv_count = getInvCount(puzzle);
- if(N & 1)
- return !(inv_count & 1);
- else {
- int pos = findXPosition(puzzle);
- if(pos & 1)
- return !(inv_count & 1);
- else
- return inv_count & 1;
- }
- }
- /*
- screen full of errors
- hello.dart:13:14: Error: A value of type 'int' can't be assigned to a variable of type 'bool'.
- Try changing the type of the left hand side, or casting the right hand side to 'bool'.
- if (arr[j] && arr[i] && arr[i] > arr[j])
- ^
- hello.dart:13:24: Error: A value of type 'int' can't be assigned to a variable of type 'bool'.
- Try changing the type of the left hand side, or casting the right hand side to 'bool'.
- if (arr[j] && arr[i] && arr[i] > arr[j])
- ^
- hello.dart:31:8: Error: A value of type 'int' can't be assigned to a variable of type 'bool'.
- Try changing the type of the left hand side, or casting the right hand side to 'bool'.
- if(N & 1)
- ^
- hello.dart:32:24: Error: A value of type 'int' can't be assigned to a variable of type 'bool'.
- Try changing the type of the left hand side, or casting the right hand side to 'bool'.
- return !(inv_count & 1);
- ^
- hello.dart:35:12: Error: A value of type 'int' can't be assigned to a variable of type 'bool'.
- Try changing the type of the left hand side, or casting the right hand side to 'bool'.
- if(pos & 1)
- ^
- hello.dart:36:26: Error: A value of type 'int' can't be assigned to a variable of type 'bool'.
- Try changing the type of the left hand side, or casting the right hand side to 'bool'.
- return !(inv_count & 1);
- ^
- hello.dart:38:24: Error: A value of type 'int' can't be assigned to a variable of type 'bool'.
- Try changing the type of the left hand side, or casting the right hand side to 'bool'.
- return inv_count & 1;
- ^
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement