blob: 5af732bc83441eb75e0da47a424848de0e26c751 (
plain)
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
|
pub fn f(input: Vec<Vec<char>>) -> u64 {
for x in 1..input[0].len() {
let mut cnt: u32 = 0;
for i in 0..input.len() {
for j in 0..x {
if 2 * x - 1 - j >= input[0].len() {
continue;
}
if input[i][j] != input[i][2 * x - 1 - j] {
cnt += 1;
}
}
}
if cnt == 1 {
return x as u64;
}
}
for y in 1..input.len() {
let mut cnt: u32 = 0;
for i in 0..y {
for j in 0..input[i].len() {
if 2 * y - 1 - i >= input.len() {
continue;
}
if input[i][j] != input[2 * y - 1 - i][j] {
cnt += 1;
}
}
}
if cnt == 1 {
return (y * 100) as u64;
}
}
panic!();
}
pub fn main() {
let txt = std::fs::read_to_string("./input/day13.txt").unwrap();
let input = txt
.split("\n\n")
.map(|s| {
s.lines()
.map(|s| s.chars().collect::<Vec<char>>())
.collect::<Vec<_>>()
})
.collect::<Vec<_>>();
let mut sum: u64 = 0;
for i in input {
sum += f(i);
}
println!("{}", sum);
}
|