-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEuler79.java
63 lines (49 loc) · 1.39 KB
/
Euler79.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
import java.io.*;
import java.util.*;
class Euler79 {
public static void main(String[] arg) {
File file = new File("Euler79.txt");
Scanner scan;
String code = "";
try {
scan = new Scanner(file);
}
catch(FileNotFoundException e) {
System.err.println("File Not Found");
return;
}
String[] combinations = new String[50];
for(int i = 0; i < combinations.length; i++)
combinations[i] = scan.nextLine();
Set<Character> done = new HashSet<Character>();
int index = 0;
a: while(index < combinations[0].length() - 1) {
Set<Character> check = new HashSet<Character>();
Set<Character> fail = new HashSet<Character>();
for(int i = 0; i < combinations.length; i++) {
Character c0 = new Character(combinations[i].charAt(index));
Character c1 = new Character(combinations[i].charAt(index + 1));
if(!done.contains(c0)) {
check.add(c0);
fail.add(c1);
}
}
for(Character c : check) {
if(!fail.contains(c)) {
done.add(c);
code += c.charValue();
continue a;
}
}
index++;
}
for(int i = 0; i < combinations.length; i++) {
Character c = new Character(combinations[i].charAt(index));
if(!done.contains(c)) {
done.add(c);
code += c;
}
}
System.out.println(code);
}
}