-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay 10-1.java
73 lines (63 loc) · 1.98 KB
/
Day 10-1.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
import java.util.Scanner; // Import the Scanner class
import java.io.File; // Import the File class
import java.util.Scanner; // Import the Scanner class
import java.io.FileNotFoundException;
import java.util.Arrays;
/**
* Write a description of class Nodes here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Main
{
static int arrSize = 91 ;
static int maxVal = 0;
public static int[] populateArray(){
int[] array = new int[arrSize];
int index = 0;
try {
File myObj = new File("puzzle.txt");
Scanner myReader = new Scanner(myObj);
while (myReader.hasNextLine()) {
String data = myReader.nextLine();
array[index] = Integer.parseInt(data);
index++;
}
myReader.close();
} catch (FileNotFoundException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
return array;
}
/**
* main method for testing outside BlueJ
*/
public static void main(String[] args) {
int[] array = populateArray();
Arrays.sort(array);
System.out.println(Arrays.toString(array));
long tot1 = 1;
long tot2 = 0;
long tot3 = 0;
long currTot = 0;
int pt = arrSize - 2;
for (int i = pt; i>=0; i--)
{
//System.out.println(array[i]);
currTot=0;
if (i+1 < arrSize && array[i+1] - array[i] <= 3)
currTot += tot1;
if (i+2 < arrSize && array[i+2] - array[i] <=3)
currTot += tot2;
if (i+3 < arrSize && array[i+3] - array[i] <=3)
currTot += tot3;
tot3 = tot2;
tot2 = tot1;
tot1 = currTot;
}
System.out.println(currTot);
maxVal = array[arrSize-1];
}
}