Compare commits
No commits in common. "1074c8d5ee9bcb45543c4150b52cd1b66c225ca3" and "d7c0ce9190037039aebb45afbbbeed8cc2726e40" have entirely different histories.
1074c8d5ee
...
d7c0ce9190
|
|
@ -121,41 +121,34 @@ pub fn solve(lines: Vec<String>, part: Part) -> u64 {
|
|||
);
|
||||
}
|
||||
|
||||
match part {
|
||||
Part::One => {
|
||||
let mut min_location = u64::MAX;
|
||||
for seed in dataset.seeds {
|
||||
let mut stage = "seed";
|
||||
let mut value = seed;
|
||||
while let Some(map) = dataset.maps.get(stage) {
|
||||
debug!("Stage {} -> {}", stage, map.target_domain);
|
||||
value = map.map(value);
|
||||
stage = &map.target_domain;
|
||||
}
|
||||
min_location = min_location.min(value);
|
||||
info!("Final stage seed {} -> location {}", seed, value);
|
||||
}
|
||||
return min_location;
|
||||
}
|
||||
Part::Two => {
|
||||
let mut min_location = u64::MAX;
|
||||
for chunk in dataset.seeds.chunks_exact(2) {
|
||||
info!("Computing range {} -> {}", chunk[0], chunk[0] + chunk[1]);
|
||||
for seed in chunk[0]..(chunk[0] + chunk[1]) {
|
||||
let mut stage = "seed";
|
||||
let mut value = seed;
|
||||
while let Some(map) = dataset.maps.get(stage) {
|
||||
debug!("Stage {} -> {}", stage, map.target_domain);
|
||||
value = map.map(value);
|
||||
stage = &map.target_domain;
|
||||
}
|
||||
min_location = min_location.min(value);
|
||||
trace!("Final stage seed {} -> location {}", seed, value);
|
||||
}
|
||||
}
|
||||
return min_location;
|
||||
if let Part::Two = part {
|
||||
// Convert the seeds to the new format !
|
||||
let original_seeds = dataset.seeds;
|
||||
let mut new_seeds : Vec<u64> = Vec::new();
|
||||
|
||||
for chunk in original_seeds.chunks_exact(2) {
|
||||
let range = chunk[0]..(chunk[0]+chunk[1]);
|
||||
// FIXME : don't do that it will eat all your memory: new_seeds.append(&mut range.collect::<Vec<u64>>());
|
||||
}
|
||||
debug!("New seeds: {:?}", new_seeds);
|
||||
|
||||
dataset.seeds = new_seeds;
|
||||
}
|
||||
|
||||
let mut min_location = u64::MAX;
|
||||
for seed in dataset.seeds {
|
||||
let mut stage = "seed";
|
||||
let mut value = seed;
|
||||
while let Some(map) = dataset.maps.get(stage) {
|
||||
debug!("Stage {} -> {}", stage, map.target_domain);
|
||||
value = map.map(value);
|
||||
stage = &map.target_domain;
|
||||
}
|
||||
min_location = min_location.min(value);
|
||||
info!("Final stage seed {} -> location {}", seed, value);
|
||||
}
|
||||
|
||||
min_location
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
Loading…
Reference in New Issue