Formatting for let else now exists

This commit is contained in:
2023-11-12 14:32:07 +01:00
parent 3522b38394
commit 10174a2915
2 changed files with 11 additions and 4 deletions

View File

@@ -110,10 +110,15 @@ impl BluePrint {
if u32::from(best - got) >= ideal_from_now { if u32::from(best - got) >= ideal_from_now {
continue; continue;
} }
assert!(todo.len() <= 1_000_000, "Safety: got a todo list of len {}, best: {best}", assert!(
todo.len()); todo.len() <= 1_000_000,
"Safety: got a todo list of len {}, best: {best}",
todo.len()
);
for (element, &costs) in self.costs.iter().enumerate() { for (element, &costs) in self.costs.iter().enumerate() {
let Some(min_to_build) = self.until_buildable(costs, resources, machines) else { break }; let Some(min_to_build) = self.until_buildable(costs, resources, machines) else {
break;
};
// +1 because we need a turn to build // +1 because we need a turn to build
let built_after = min_to_build + 1; let built_after = min_to_build + 1;

View File

@@ -136,7 +136,9 @@ pub fn part1(input: &[u8]) -> Result<String> {
pub fn part2(input: &[u8]) -> Result<String> { pub fn part2(input: &[u8]) -> Result<String> {
let monkeys = parse_input(input, parse_monkeys)?; let monkeys = parse_input(input, parse_monkeys)?;
let Monkey::Operation(first, second, _) = &monkeys[&b"root"[..]] else { anyhow::bail!("root is a literal somehow")}; let Monkey::Operation(first, second, _) = &monkeys[&b"root"[..]] else {
anyhow::bail!("root is a literal somehow")
};
let result = match (evaluate2(&monkeys, first), evaluate2(&monkeys, second)) { let result = match (evaluate2(&monkeys, first), evaluate2(&monkeys, second)) {
(Ok(_), Ok(_)) => anyhow::bail!("both arms succeeded"), (Ok(_), Ok(_)) => anyhow::bail!("both arms succeeded"),