-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62505c2
commit 43ad1f6
Showing
4 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
|
||
namespace AoC2018.Solutions.Day15 | ||
{ | ||
public class Part02 : ISolution | ||
{ | ||
public string Solve(string input) | ||
{ | ||
////Console.WriteLine(currentState.ToString()); | ||
|
||
int attackStrength = 4; | ||
|
||
while (true) | ||
{ | ||
////Console.WriteLine($"Running with hit points = {attackStrength}"); | ||
|
||
var currentState = State.Parse(input); | ||
Elf[] elves = currentState.GetUnits<Elf>(); | ||
int elfCount = elves.Length; | ||
|
||
// Set their hit count | ||
foreach (Elf current in elves) | ||
{ | ||
current.AttackStrength = attackStrength; | ||
} | ||
|
||
int rounds = 0; | ||
bool deadElves = false; | ||
|
||
while (!deadElves) | ||
{ | ||
bool roundCompleted = currentState.Round(); | ||
|
||
if (roundCompleted) | ||
{ | ||
rounds++; | ||
} | ||
|
||
deadElves = currentState.CountUnits<Elf>() < elfCount; | ||
|
||
if (currentState.IsCombatEnded()) | ||
{ | ||
break; | ||
} | ||
} | ||
|
||
if (deadElves) | ||
{ | ||
////Console.WriteLine($"Elves died during round {rounds}"); | ||
attackStrength++; | ||
} | ||
else | ||
{ | ||
return (rounds * currentState.TotalRemainingHitPoints()).ToString(); | ||
} | ||
} | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters