# Does it use this approach? I heard there is better way but I am kinda stupid
def get_highest_jolt(b: str) -> int:
jolt_str = ""
digit_index = 0
# Find largest digit in b leaving enough string to grab later
# so we prioritize having at least 12 digits, then largest digit
# highness which should make the biggest number possible
for i in range(1, 13):
largest_digit = -1
remaining = 12 - i
slice_to = -remaining if remaining > 0 else None
best_jump_index = 0
for index, c in enumerate(b[digit_index:slice_to]):
if int(c) > largest_digit:
largest_digit = int(c)
best_jump_index = index+1
jolt_str += str(largest_digit)
digit_index += best_jump_index
return jolt_str
The approach shown uses a stack. While the joltage on the last battery on the stack is smaller than the current battery's joltage, the batteries are popped off the stack (so long as we have enough batteries left in the bank to fill the stack), then the current battery is added to the stack if there's room.
Looks roughly like my logic. I found it perfectly adequate and straightforward. Don't really care if there's a "better" way. Got to bed at a reasonable time.
22
u/danmaps Dec 03 '25
Beautiful
18
u/Negative_Breath2618 Dec 03 '25
Really clever implementation and super fun visual!
14
u/Dry-Newt464 Dec 03 '25
So stack huh,, thanks for this visualization!
7
u/Sufficient_Age404040 Dec 03 '25
This is definitely the best visualization of the algorithm so far.
6
u/daggerdragon Dec 03 '25
I see
Visualizationby /u/naclmolecule, I upvote.5
u/nik282000 Dec 03 '25
Man am I dumb! That's a way smarter approach than I took >_<
4
u/abishekdevendran Dec 03 '25
That's actually super cool!
4
u/fractioneater Dec 03 '25
Be careful how you dispose of batteries.
1
u/[deleted] Dec 03 '25
2
u/BananaMilkshake66 Dec 03 '25
This is brilliant
1
u/ObnoxiouslyVivid Dec 03 '25
Reminds me of gnorp
1
u/Landcruiser82 Dec 03 '25
Your visuals are always fun! Thanks for making these!
1
u/FuzzyWuzzyWasABeer Dec 04 '25
Such a great visual!
1
u/TheDextermin Dec 04 '25
I love that look!
1
u/rjwut Dec 09 '25
Heck yeah, NaCl is backle!
1
u/Gers_2017 Dec 22 '25
Exquisite visualization.