-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4p1.txt
More file actions
32 lines (29 loc) · 949 Bytes
/
4p1.txt
File metadata and controls
32 lines (29 loc) · 949 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
32
public class Part1 {
private static int valid = 0;
public static void main(String[] args) {
try (Stream<String> stream = Files.lines(Paths.get("E:\\AdventOfCode\\Day 4\\input.txt"))) {
stream.forEach(string -> {
if (isValid(string)) {
valid++;
System.out.println("Valid: " + string);
} else {
System.out.println("Invalid: " + string);
}
});
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Result:\n " + valid);
}
private static boolean isValid(String word) {
List<String> parts = new ArrayList<>();
for (String part : word.split(" ")) {
if (!parts.contains(part)) {
parts.add(part);
} else {
return false;
}
}
return true;
}
}