[DOC] Some more comments to explain why this works
This commit is contained in:
@@ -97,7 +97,7 @@ impl DaySolver for Day8 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// println!("Start node {}, after {}: {:?}", start_node, i, end_times);
|
// println!("Start node {}, after {} with period {}: {:?}", start_node, i, end_times[1]-end_times[0], end_times);
|
||||||
periods_per_start_node.push(Period {
|
periods_per_start_node.push(Period {
|
||||||
start: BigInt::from(end_times[0]),
|
start: BigInt::from(end_times[0]),
|
||||||
repeat: BigInt::from(end_times[1] - end_times[0])
|
repeat: BigInt::from(end_times[1] - end_times[0])
|
||||||
@@ -106,6 +106,7 @@ impl DaySolver for Day8 {
|
|||||||
|
|
||||||
// Now we just need to find out when these periods fall at the same time
|
// Now we just need to find out when these periods fall at the same time
|
||||||
// This appears to be the LCM of all periods
|
// This appears to be the LCM of all periods
|
||||||
|
// This only works because the period and start are the same for each sequence we got...
|
||||||
let mut solution_period: Period = periods_per_start_node.first().unwrap().to_owned();
|
let mut solution_period: Period = periods_per_start_node.first().unwrap().to_owned();
|
||||||
for period in periods_per_start_node.iter().skip(1) {
|
for period in periods_per_start_node.iter().skip(1) {
|
||||||
solution_period = Period {
|
solution_period = Period {
|
||||||
@@ -113,7 +114,6 @@ impl DaySolver for Day8 {
|
|||||||
repeat: solution_period.repeat.lcm(&period.repeat)
|
repeat: solution_period.repeat.lcm(&period.repeat)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// note: I don't understand why we can just ignore how long it takes to get to the end the first time...
|
|
||||||
|
|
||||||
// let mut i = 0usize;
|
// let mut i = 0usize;
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user