rust: Optimisations
This commit is contained in:
parent
8efa00bd48
commit
834c86e09a
1 changed files with 8 additions and 15 deletions
|
@ -592,7 +592,7 @@ mod day16 {
|
|||
.next()
|
||||
.unwrap()
|
||||
.split(",")
|
||||
.flat_map(str::parse)
|
||||
.map(|s| s.parse().unwrap())
|
||||
.collect();
|
||||
|
||||
lines.next(); // ""
|
||||
|
@ -600,7 +600,7 @@ mod day16 {
|
|||
|
||||
let mut nearby_tickets: Vec<Ticket> = Vec::new();
|
||||
while let Some(line) = lines.next() {
|
||||
nearby_tickets.push(line.split(",").flat_map(str::parse).collect());
|
||||
nearby_tickets.push(line.split(",").map(|s| s.parse().unwrap()).collect());
|
||||
}
|
||||
|
||||
let mut part1 = 0;
|
||||
|
@ -629,20 +629,13 @@ mod day16 {
|
|||
.collect();
|
||||
|
||||
for ticket in valid_tickets {
|
||||
for (field, possibilities) in ticket.iter().zip(field_possibilities.iter_mut()) {
|
||||
for rule_i in possibilities.clone().iter() {
|
||||
let rule = &rules[*rule_i];
|
||||
if !((field >= &rule.ranges.0.from && field <= &rule.ranges.0.to)
|
||||
|| (field >= &rule.ranges.1.from && field <= &rule.ranges.1.to))
|
||||
{
|
||||
for (&field, possibilities) in ticket.iter().zip(field_possibilities.iter_mut()) {
|
||||
possibilities
|
||||
.iter()
|
||||
.position(|i| i == rule_i)
|
||||
.position(|&rule_i| !rules[rule_i].validate(field))
|
||||
.map(|i| possibilities.remove(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut part2 = 1;
|
||||
loop {
|
||||
|
@ -663,7 +656,7 @@ mod day16 {
|
|||
}
|
||||
|
||||
let rule = &rules[possibility].name;
|
||||
if rule.starts_with("departure") {
|
||||
if rule.starts_with("de") {
|
||||
part2 *= your_ticket[i];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue