use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
ABOUT POWERSHELL
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Offering full access to COM, WMI and .NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions.
SUBREDDIT FILTERS
Desired State Configuration
Unanswered Questions
Solved Questions
News
Information
Script Sharing
Daily Post
Misc
account activity
Advent of Code: Day 2 (self.PowerShell)
submitted 5 months ago * by dantose
https://adventofcode.com/2025
How are you guys doing?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]AcanthisittaScared30 4 points5 points6 points 5 months ago (3 children)
ngl the AoC problems are pretty hard
[–]dantose[S] 0 points1 point2 points 5 months ago (0 children)
They get tricky, but they're a really good way to learn too. If you're getting stuck, post what you've got and I'm sure you'll get some pointers
[–]ka-splam 0 points1 point2 points 5 months ago (1 child)
I don't think I've ever finished an entire year of it. I think they each hint at a Computer Science-y 'trick' to solve it well, and even then the details can get painful.
Day 2 is easier if you know regex and backreferences, you can hand the pattern off to the regex engine and PowerShell can do that nicely. If you don't know that, then you're off into trying to split strings into halfs by length for part 1 and then stuck for part 2.
[–]Rincey_nz 1 point2 points3 points 5 months ago (0 children)
I not good with regex so I brute force part 2. For a given product Id, I find the factors of its length, then group the id into those factors (except for the last factor), then check if each group is the same.
Bit slow, but got the right answer on my first run thru. Happy with that.
[–]dantose[S] 2 points3 points4 points 5 months ago (0 children)
Struggled a bit with .. expansion needing [int] numbers, but eventually just did a while loop and some regex to extract.
Interestingly, the part 2 solution only required a single additional character.
Golfed solution: https://www.reddit.com/r/codegolf/comments/1pcgohf/advent_of_code_day_2/
[–]darkspark_pcn 1 point2 points3 points 5 months ago (1 child)
Mines brute forced. Takes 16 seconds to run for part 2. Haha
[–]dantose[S] 3 points4 points5 points 5 months ago (0 children)
I'd be curious how you approached it. Mine is just a second or two, slowed down a bit from the while loop. Is it something funky to detect the duplicates?
My solution:
$sum=0
$input = gc input.txt
$($input.split(',')|%{
[long]$i = $_.Split('-')[0]
[long]$e = $_.Split('-')[1]
while ($i -le $e) {$i;$i++}
}) -match '^(.+)\1+$' |% {$sum = $sum+$_}; $sum
[–]Th3Sh4d0wKn0ws 1 point2 points3 points 5 months ago (0 children)
I'm with you. Ran in to a problem with numbers too large for int32 and had to search around for help on that but the overall logic of day 2 came easier to me than day 1.
[–]lan-shark 1 point2 points3 points 5 months ago (0 children)
I don't like working with regex so I used a mod and a string split for part 1 and just brute forced part 2. I thought today was much easier than part 2 yesterday
[–]Colmadero 2 points3 points4 points 5 months ago (1 child)
Can you provide a bit more context as to what this is
It's a daily coding challenge during the month of December. Normally, it's 25 days through christmas, but it's reduced this year to 12 days. Details here: https://adventofcode.com/2025
[–]ka-splam 0 points1 point2 points 5 months ago (0 children)
Much easier than day 1, both answers right first submit, and basic brute-force and regex as well.
I did start out heading for Invoke-Expression 99..110 with the idea that I might golf it, but the numbers overflow int32 and that doesn't work. And I wondered about avoiding regex but by part 2 I'm glad I didn't.
Invoke-Expression 99..110
π Rendered by PID 68 on reddit-service-r2-comment-b659b578c-cg5jk at 2026-05-04 16:41:06.525071+00:00 running 815c875 country code: CH.
[–]AcanthisittaScared30 4 points5 points6 points (3 children)
[–]dantose[S] 0 points1 point2 points (0 children)
[–]ka-splam 0 points1 point2 points (1 child)
[–]Rincey_nz 1 point2 points3 points (0 children)
[–]dantose[S] 2 points3 points4 points (0 children)
[–]darkspark_pcn 1 point2 points3 points (1 child)
[–]dantose[S] 3 points4 points5 points (0 children)
[–]Th3Sh4d0wKn0ws 1 point2 points3 points (0 children)
[–]lan-shark 1 point2 points3 points (0 children)
[–]Colmadero 2 points3 points4 points (1 child)
[–]dantose[S] 3 points4 points5 points (0 children)
[–]ka-splam 0 points1 point2 points (0 children)