Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d430eaf

Browse files
Account for remainder in 2015 Day 21
1 parent e89137b commit d430eaf

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

‎src/year2015/day21.rs‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,18 @@ pub fn parse(input: &str) -> Vec<Result> {
7474
for &third in &combinations {
7575
let Item { cost, damage, armor } = first + second + third;
7676

77-
let hero_turns = boss_health / (damage - boss_armor).max(1);
78-
let boss_turns = 100 / (boss_damage - armor).max(1);
77+
let hero_hit = (damage - boss_armor).max(1);
78+
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+
} else {
87+
100 / boss_hit + 1
88+
};
7989
let win = hero_turns <= boss_turns;
8090

8191
results.push((win, cost));

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /