-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay 10.java
115 lines (98 loc) · 2.86 KB
/
Day 10.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import java.io.File;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.util.*;
class Main {
private static List<Integer> intList;
private static int[] x;
public static void main(String[] args) {
x = populateArray();
Arrays.sort(x);
System.out.println(Arrays.toString(x));
//System.out.println(firstStar(x));
int index = 0;
intList = new ArrayList<Integer>(x.length);
for (int i : x)
{
intList.add(i);
}
System.out.println("possible soultions: " + secondStar(index));
}
public static boolean firstStar(int[] x){
int oneDiff = 0;
int twoDiff = 0;
int threeDiff = 0;
for (int i = 0; i < x.length-1; i ++){
int diff = x[i+1] - x[i];
if (diff == 1){
oneDiff++;
} else if (diff == 2){
twoDiff++;
} else if (diff == 3){
threeDiff++;
} else if (diff > 3){
System.out.println(oneDiff);
System.out.println("reached max value");
return false;
}
}
oneDiff++;
threeDiff++;
System.out.println("one: " + oneDiff);
System.out.println("two: " + twoDiff);
System.out.println("three: " + threeDiff);
return true;
}
public static int secondStar(int index){
int numOfPossible = 0;
//for (int i = index; i < x.length-2; i ++){
//System.out.println(intList);
int currVal = x[index];
//System.out.println(currVal);
for (int j = 1; j <= 3; j++){
intList = new ArrayList<Integer>();
for (int i = index; i < index+3; i++){
try{
intList.add(x[i]);
} catch(Exception e){
}
}
int testVal = currVal +j;
if (intList.contains(testVal)){
//System.out.println("here");
//System.out.println("test value: " + testVal);
index++;
//System.out.println("temp index: " + index);
//System.out.println("index: " + tempIndex + " length: " + (x.length-2));
if(index == x.length-1){
//System.out.println("got here");
numOfPossible++;
//return numOfPossible;
} else if(index<x.length-1){
//System.out.println("index: " + index);
numOfPossible+=secondStar(index);
}
}
}
//}
return numOfPossible;
}
public static int[] populateArray(){
int[] array = new int[91];
int index = 0;
try {
File myObj = new File("puzzle.txt");
Scanner myReader = new Scanner(myObj);
while (myReader.hasNextLine()) {
int data = Integer.parseInt(myReader.nextLine());
array[index] = data;
index++;
}
myReader.close();
} catch (FileNotFoundException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
return array;
}
}