r/PowerShell • • Dec 04 '25

Misc Advent of Code - Day 3

was waiting for u/dantose to make this post ;)

I'm running a day behind, so have only just got to Day 3 Part 2 (Part 1 stumped me because I misread it - I was adding max1 and max2 for each battery bank together as integers, whereas I needed to concat them as strings....

Still, Part 2 has me so stumped I can't even work out how to start :(

7 Upvotes

12 comments sorted by

View all comments

Show parent comment

2

u/OPconfused Dec 05 '25
@'
987654321111111
811111111111119
234234234234278
818181911112111
'@ -split "`n" | get-maxvoltage -MaxDigits 2
357

Works for me?

and 12 got me:

3121910778619 as you expected

3

u/surfingoldelephant Dec 05 '25

They're probably using PS ISE, which uses CRLF line endings (unlike the PS console host, which uses LF). 207/2001910778619 is the result if you process each line of the example with a trailing \r included.

u/pandiculator, make sure you're splitting the input on the correct line ending. If you use \r?\n, you'll find u/OPconfused's code works correctly irrespective of your PowerShell host.

@'
987654321111111
811111111111119
234234234234278
818181911112111
'@ -split '\r?\n' | Get-MaxVoltage -MaxDigits 2 # 357

1

u/pandiculator Dec 05 '25

Thanks, changing the regex fixed it. I'm using VSCode.

1

u/pandiculator Dec 05 '25

/u/surfingoldelephant correctly identified why it wasn't working for me.

Very neat solution.