From 439cad4dc85f5780f5426c187ab0aee510716986 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Mon, 24 Dec 2018 08:57:42 +0100 Subject: [PATCH] Implement day 24 part 1. --- 2018/inputs/24.txt | 23 +++++++++++++++++++++++ 2018/src/day24.rs | 5 +---- 2 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 2018/inputs/24.txt diff --git a/2018/inputs/24.txt b/2018/inputs/24.txt new file mode 100644 index 0000000..2fa319e --- /dev/null +++ b/2018/inputs/24.txt @@ -0,0 +1,23 @@ +Immune System: +1614 units each with 8016 hit points (immune to slashing; weak to radiation) with an attack that does 48 fire damage at initiative 9 +3730 units each with 5611 hit points (immune to bludgeoning; weak to fire) with an attack that does 14 radiation damage at initiative 16 +1627 units each with 9770 hit points (weak to cold) with an attack that does 55 fire damage at initiative 3 +4665 units each with 9782 hit points (weak to fire) with an attack that does 18 radiation damage at initiative 10 +281 units each with 5764 hit points (immune to fire; weak to radiation) with an attack that does 187 slashing damage at initiative 19 +524 units each with 9344 hit points with an attack that does 158 cold damage at initiative 15 +5013 units each with 9768 hit points with an attack that does 15 cold damage at initiative 14 +1143 units each with 1822 hit points (weak to radiation) with an attack that does 15 fire damage at initiative 18 +136 units each with 6830 hit points (weak to radiation) with an attack that does 420 slashing damage at initiative 7 +665 units each with 7973 hit points (weak to bludgeoning; immune to slashing) with an attack that does 119 fire damage at initiative 11 + +Infection: +515 units each with 8712 hit points (immune to radiation; weak to slashing, fire) with an attack that does 30 cold damage at initiative 1 +5542 units each with 56769 hit points with an attack that does 16 bludgeoning damage at initiative 4 +1663 units each with 10437 hit points (immune to slashing, fire, radiation) with an attack that does 12 radiation damage at initiative 12 +574 units each with 50124 hit points (weak to slashing, radiation) with an attack that does 171 fire damage at initiative 8 +1190 units each with 10652 hit points with an attack that does 16 cold damage at initiative 17 +3446 units each with 23450 hit points with an attack that does 12 fire damage at initiative 5 +5887 units each with 14556 hit points (weak to slashing) with an attack that does 4 radiation damage at initiative 2 +1761 units each with 41839 hit points (weak to cold) with an attack that does 35 cold damage at initiative 20 +4194 units each with 16090 hit points (immune to fire; weak to slashing) with an attack that does 6 fire damage at initiative 6 +2127 units each with 27065 hit points (weak to cold, slashing) with an attack that does 24 slashing damage at initiative 13 diff --git a/2018/src/day24.rs b/2018/src/day24.rs index 91003e5..cbc55ec 100644 --- a/2018/src/day24.rs +++ b/2018/src/day24.rs @@ -128,7 +128,7 @@ impl Day24 { } let damage = self.units.iter().map(|x| unit.damage_to(x)).collect_vec(); let target = (0..self.units.len()) - .filter(|&x| !is_targeted[x] && self.units[x].faction != unit.faction) + .filter(|&x| !is_targeted[x] && self.units[x].faction != unit.faction && self.units[x].is_alive()) .max_by(|&x, &y| { damage[x].cmp(&damage[y]) .then(self.units[x].effective_power().cmp(&self.units[y].effective_power())) @@ -136,14 +136,12 @@ impl Day24 { }); if let Some(target) = target { - println!("{} will attack {}, dealing {}", i, target, damage[target]); targets[i] = Some(target); is_targeted[target] = true; } } order.sort_unstable_by_key(|&x| Reverse(self.units[x].initiative)); - println!("{:?}", order); for attacker in order { if !self.units[attacker].is_alive() { @@ -155,7 +153,6 @@ impl Day24 { let defender = &mut self.units[id]; let losses = damage / defender.hp; - println!("{} does {} damage to {}. Killed {}", attacker, damage, id, losses); defender.count = defender.count.saturating_sub(losses); } }