Compare commits
1 commit
6921d46db3
...
70184751e6
Author | SHA1 | Date | |
---|---|---|---|
Tristan Daniël Maat | 70184751e6 |
|
@ -7,7 +7,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
|
||||
// Part 1
|
||||
let result = chain_all(&jolts);
|
||||
println!("{}", result.0 * result.1);
|
||||
println!("{}", result.0 * result.2);
|
||||
|
||||
// Part 2
|
||||
let result = count_possible_chains(&jolts)?;
|
||||
|
@ -55,9 +55,11 @@ fn count_possible_chains(jolts: &Vec<u64>) -> Result<u64, std::num::TryFromIntEr
|
|||
.product()
|
||||
}
|
||||
|
||||
fn chain_all(jolts: &Vec<u64>) -> (usize, usize) {
|
||||
fn chain_all(jolts: &Vec<u64>) -> (usize, usize, usize) {
|
||||
let mut jolts = jolts.to_vec();
|
||||
// Add input jolts
|
||||
jolts.push(0);
|
||||
// Add output jolts
|
||||
jolts.sort();
|
||||
jolts.push(jolts.last().expect("Need some jolts") + 3);
|
||||
|
||||
|
@ -73,9 +75,10 @@ fn chain_all(jolts: &Vec<u64>) -> (usize, usize) {
|
|||
.collect();
|
||||
|
||||
let jump_1s = jolt_jumps.iter().filter(|e| **e == 1).count();
|
||||
let jump_2s = jolt_jumps.iter().filter(|e| **e == 2).count();
|
||||
let jump_3s = jolt_jumps.iter().filter(|e| **e == 3).count();
|
||||
|
||||
(jump_1s, jump_3s)
|
||||
(jump_1s, jump_2s, jump_3s)
|
||||
}
|
||||
|
||||
fn parse_jolts(input: &str) -> Result<Vec<u64>, std::num::ParseIntError> {
|
||||
|
@ -107,7 +110,7 @@ mod tests {
|
|||
let jolts = parse_jolts(input)?;
|
||||
let result = chain_all(&jolts);
|
||||
|
||||
assert_eq!(result.0 * result.1, 7 * 5);
|
||||
assert_eq!(result.0 * result.2, 7 * 5);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -151,7 +154,7 @@ mod tests {
|
|||
let jolts = parse_jolts(input)?;
|
||||
let result = chain_all(&jolts);
|
||||
|
||||
assert_eq!(result.0 * result.1, 22 * 10);
|
||||
assert_eq!(result.0 * result.2, 22 * 10);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue