Skip to content

Commit

Permalink
optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaKateryna committed Dec 6, 2023
1 parent 9076c53 commit 094f442
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion AdventOfCode/Day06.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ private long GetWaysToWin(Race race)
for (long i = 0; i < race.Time; ++i)
{
long distance = (race.Time - i) * i;
waysToWin += distance > race.Distance ? 1 : 0;
if (distance > race.Distance)
{
waysToWin++;
}
else if (waysToWin > 0)
{
break;
}
}
return waysToWin;
}
Expand Down

0 comments on commit 094f442

Please sign in to comment.