Skip to content

Commit 60448b9

Browse files
Update docs on Wed Dec 3 07:03:07 UTC 2025
1 parent b055250 commit 60448b9

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

2025/3/index.html

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,6 @@ <h2 id="problem-name">Lobby</h2>
278278
</div>
279279
<div id="code-container"><pre class="hljs language-csharp"><code>namespace AdventOfCode.Y2025.Day03;
280280

281-
using System;
282281
using System.Linq;
283282

284283
[ProblemName(&quot;Lobby&quot;)]
@@ -290,25 +289,17 @@ <h2 id="problem-name">Lobby</h2>
290289
public long MaxJoltSum(string input, int batteryCount) =&gt;
291290
input.Split(&quot;\n&quot;).Select(bank =&gt; MaxJolt(bank, batteryCount)).Sum();
292291

293-
// Determines the maximum possible jolt value by selecting `batteryCount`
294-
// digits in descending order from `bank` while preserving order.
295292
long MaxJolt(string bank, int batteryCount) {
296-
if (batteryCount == 0) {
297-
return 0;
298-
}
299-
if (bank.Length &lt; batteryCount) {
300-
return -1;
301-
}
302-
for (int jolt = 9; jolt &gt; 0; jolt--) {
303-
var index = bank.IndexOf((char)(jolt + &#039;0&#039;));
304-
if (index &gt;= 0) {
305-
var res = MaxJolt(bank[(index + 1)..], batteryCount - 1);
306-
if (res &gt;= 0) {
307-
return jolt * (long)Math.Pow(10, batteryCount-1) + res;
308-
}
309-
}
310-
}
311-
throw new Exception();
293+
long res = 0L;
294+
for (; batteryCount &gt; 0; batteryCount--) {
295+
// jump forward to the highest available digit in the bank, but keep
296+
// batteryCount digits in the suffix, so that we can select something
297+
// for those remaining batteries as well.
298+
char jolt = bank[..^(batteryCount - 1)].Max();
299+
bank = bank[(bank.IndexOf(jolt) + 1)..];
300+
res = 10 * res + (jolt - &#039;0&#039;);
301+
}
302+
return res;
312303
}
313304
}</code></pre></div>
314305
<div id="code-location"> <p>Please ☆ my <a href="https://github.com/encse/adventofcode/">repo</a> if you like it!</p></div>

0 commit comments

Comments
 (0)