Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.HashSet;
- import java.util.Set;
- public class Solver {
- int [][] input;
- int[] added = {0, 1, 2, 9, 10, 11, 18, 19, 20};
- ArrayList<ArrayList<Integer>> aid = new ArrayList<>(81);
- Boolean change = true;
- Boolean second = true;
- Solver(int[][] solve){
- input = solve;
- for (int i = 0; i<81; i++){
- aid.add(new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9)));
- }
- }
- private void fuck(Integer al1, Integer al2, Integer a13, Integer a14, Set<ArrayList> okay) {
- if( aid.get((al1/3)*27+((al2/3)*3+a13)).size()==2){
- if (!(okay.add(aid.get((al1 / 3) * 27 + (al2 / 3)*3+a13)))) {
- for (int i : added) {
- if (!(aid.get((al1 / 3) * 27 + (al2 / 3) * 3 + a13).equals(aid.get((al1 / 3) * 27 + (al2 / 3) * 3 + i)))) {
- for (int d : aid.get((al1 / 3) * 27 + (al2 / 3) * 3 + a13)) {
- if (aid.get((al1 / 3) * 27 + (al2 / 3) * 3 + i).remove(Integer.valueOf(d))) second = true;
- }
- }
- }
- }
- }
- }
- private void checkIfOne(int i, int j){
- if (aid.get(i*9+j).size() == 1){
- input[i][j] = aid.get(i*9+j).get(0);
- aid.get(i*9+j).remove(0);
- change = true;
- second = true;
- }
- }
- void solve(){
- change = false;
- for (int i = 0; i < 9; i++){
- for(int j = 0; j < 9; j++){
- if (input[i][j]!= 0){
- aid.get(i*9+j).clear();
- for (int c = 0; c < 9; c++){
- if( aid.get(i*9+c).remove(Integer.valueOf(input[i][j]))){
- change = true;
- second=true;
- }
- if( aid.get(c*9+j).remove(Integer.valueOf(input[i][j]))){
- second=true;
- change = true;
- }
- }
- for (int g: added){
- if(aid.get((i/3)*27+(j/3)*3+g).remove(Integer.valueOf(input[i][j]))) {
- change=true;
- second = true;
- }
- }
- }
- checkIfOne(i,j);}
- }}
- void hardSolve(){
- for (int i = 0; i < 9; i++){
- Set<ArrayList> usedNums = new HashSet<>();
- for (int j = 0; j < 9; j++){
- if (aid.get(i*9+j).size() == 2){
- if(! usedNums.add(aid.get(i*9+j))){
- for (int c = 0; c < 9; c++){
- if(!(aid.get(i*9+c).equals(aid.get(i*9+j)))){
- for (int d : aid.get(i*9+j)){
- if(aid.get(i*9+c).remove(Integer.valueOf(d))){
- change = true;
- second=true;
- }
- System.out.println("test");
- System.out.println(aid.get(58));
- }
- }
- }
- }
- }
- checkIfOne(i,j);}
- }
- for (int j = 0; j < 9; j++){
- Set<ArrayList> usedNums = new HashSet<>();
- for (int i = 0; i < 9; i++){
- if (aid.get(i*9+j).size() == 2){
- if(! usedNums.add(aid.get(i*9+j))){
- for (int c = 0; c < 9; c++){
- if(!(aid.get(c*9+j).equals(aid.get(i*9+j)))){
- for (int d : aid.get(i*9+j)){
- if(aid.get(c*9+j).remove(Integer.valueOf(d))) change = true;
- System.out.println("test");
- }
- }
- }
- }
- }
- }
- }
- for (int i = 0; i < 9; i++){
- for (int j = 0; j < 9; j++){
- Set<ArrayList> usedNums = new HashSet<>();
- for (int d : added){
- for (int g : added){
- fuck(i,j,d,g,usedNums);
- }
- }
- }
- }
- for (int i = 0; i < 9; i++){
- for (int j = 0; j < 9; j++) {
- checkIfOne(i, j);
- }
- }solve();}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement