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