We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e89137b commit d430eafCopy full SHA for d430eaf
src/year2015/day21.rs
@@ -74,8 +74,18 @@ pub fn parse(input: &str) -> Vec<Result> {
74
for &third in &combinations {
75
let Item { cost, damage, armor } = first + second + third;
76
77
- let hero_turns = boss_health / (damage - boss_armor).max(1);
78
- let boss_turns = 100 / (boss_damage - armor).max(1);
+ let hero_hit = (damage - boss_armor).max(1);
+ let hero_turns = if boss_health % hero_hit == 0 {
79
+ boss_health / hero_hit
80
+ } else {
81
+ boss_health / hero_hit + 1
82
+ };
83
+ let boss_hit = (boss_damage - armor).max(1);
84
+ let boss_turns = if 100 % boss_hit == 0 {
85
+ 100 / boss_hit
86
87
+ 100 / boss_hit + 1
88
89
let win = hero_turns <= boss_turns;
90
91
results.push((win, cost));
0 commit comments