-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path079.PasscodeDerivation.java
More file actions
31 lines (30 loc) · 990 Bytes
/
Copy path079.PasscodeDerivation.java
File metadata and controls
31 lines (30 loc) · 990 Bytes
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
import java.io.*;
import java.util.*;
class PasscodeDerivation {
public static void main(String[] args) throws FileNotFoundException {
var a = Arrays.stream(new Scanner(new File("p079_keylog.txt")).useDelimiter("\\Z").next().split("\n")).map(s -> s.chars().map(c -> c - '0').toArray()).toArray(int[][]::new);
int[][] after = new int[10][10];
for(var b : a) {
after[b[0]][b[1]]++;
after[b[0]][b[2]]++;
after[b[1]][b[2]]++;
}
int[][] an = new int[10][2];
for(int i = 0; i < 10; i++) {
an[i][0] = i;
an[i][1] = (int)Arrays.stream(after[i]).filter(n -> n != 0).count();
}
Arrays.sort(an, Comparator.comparingInt(o -> o[1]));
StringBuilder s = new StringBuilder();
for(var x : an) {
int count = 0;
for(int i = 0; i < 10; i++) {
count += after[i][x[0]];
}
if(count != 0 || x[1] > 0) {
s.insert(0, x[0]);
}
}
System.out.println(s);
}
}