Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b5f4a02

Browse files
committed
Day 2 intermediate
1 parent 84e7926 commit b5f4a02

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/bin/day21.rs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,7 @@ fn collect_paths(source: Pos, code: &Vec<Vec<char>>) -> Vec<Vec<char>> {
107107
res
108108
}
109109

110-
fn main() {
111-
let start = Instant::now();
112-
let mut input = AocInput::new("inputs/day21.txt");
113-
110+
fn part1(input: &mut AocInput) {
114111
let mut total = 0;
115112
for line in input.read_lines() {
116113
let chars: Vec<char> = line.chars().collect();
@@ -122,6 +119,30 @@ fn main() {
122119
total += value * costs;
123120
}
124121
println!("Part 1: {}", total);
122+
}
123+
124+
fn part2(input: &mut AocInput) {
125+
let mut total = 0;
126+
for line in input.read_lines() {
127+
let chars: Vec<char> = line.chars().collect();
128+
let value: i64 = line[..line.len() - 1].parse().unwrap();
129+
let mut s = num_pad_paths(Pos(2, 3), &chars);
130+
for _ in 0..3 {
131+
s = collect_paths(Pos(2, 0), &s)
132+
}
133+
let costs = s.iter().map(|p| p.len() as i64).min().unwrap();
134+
total += value * costs;
135+
}
136+
println!("Part 2: {}", total);
137+
}
138+
139+
140+
fn main() {
141+
let start = Instant::now();
142+
let mut input = AocInput::new("inputs/tst2.txt");
143+
part1(&mut input);
144+
input.reset();
145+
part2(&mut input);
125146

126147
let duration = start.elapsed();
127148
println!("Time: {:?}", duration);

0 commit comments

Comments
 (0)