-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.ndc
57 lines (46 loc) · 904 Bytes
/
2.ndc
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
lines = read_file("input/2").lines();
two, three := 0, 0;
for line in lines {
has_two, has_three := false, false;
for c in "abcdefghijklmnopqrstuvwxyz" {
count := [ 1 for cc in line, if cc == c ].sum();
if count == 2 {
has_two = true;
} else if count == 3 {
has_three = true;
}
}
if has_two {
two += 1;
}
if has_three {
three += 1;
}
}
print("Part 1:", two * three);
fn part2() {
for v in lines, vv in lines {
idx := 0;
len := v.len();
diff := 0;
while idx < len and diff <= 1 {
if v[idx] != vv[idx] {
diff += 1;
}
idx += 1;
}
// if diff is exactly one
if diff == 1 {
idx = 0;
ans := "";
while idx < len {
if v[idx] == vv[idx] {
ans.append(vv[idx]);
}
idx += 1;
}
return ans;
}
}
}
print("Part 2:", part2());