-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay6.java
More file actions
65 lines (61 loc) · 1.65 KB
/
Day6.java
File metadata and controls
65 lines (61 loc) · 1.65 KB
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
import java.io.*;
import java.util.*;
import static java.util.Arrays.asList;
import static java.util.Arrays.compareUnsigned;
public class Day6 {
static List<String> lines = new ArrayList<>();
String input6 = "input6";
public void readFile(){
try{
File file = new File(input6);
Scanner input = new Scanner(file);
while(input.hasNext()) {
String line = input.nextLine();
lines.add(line);
}
System.out.println(lines);
} catch (Exception e) {
e.printStackTrace();
}
}
public void letterCount(){
int count = 0;
Map<Character, Integer> map = new HashMap<>();
for(String letter : lines){
for(char c : letter.toCharArray()){
if(!map.containsKey(c)){
int counter;
counter = map.get(c);
map.put(c, ++counter);
}
else{
map.put(c,1);
}
}
}
for(char c : map.keySet()){
if(map.get(c) == 1){
count += 1;
}
}
System.out.println(count);
}
public void reading() throws IOException {
File file = new File("input6");
BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
String st;
while ((st = bufferedReader.readLine()) != null)
System.out.println(st);
}
public void sum1Letters(){
long sum = Arrays.stream(lines.toString().split(", ,"))
.map(i -> i.replace(",",""))
.mapToLong(i -> i.chars().distinct().count()).sum();
System.out.println(sum);
}
public static void main(String[] args) throws IOException {
Day6 day6 = new Day6();
day6.readFile();
day6.sum1Letters();
}
}