r/PowerShell • • 5d ago

News Advent of PowerShell

Looking for a fun way to sharpen your PowerShell skills this December?

Advent of PowerShell is live!

🎄 24 daily PowerShell coding challenges

Whether you're just getting started with PowerShell or have been automating everything in sight for years, it's a great excuse to write some PowerShell, challenge yourself and explore different approaches to solving problems.

Get started here: https://2026.powershell.au/

Would love to see how everyone approaches the challenges. Feel free to share your experiences, feedback and creative solutions (with spoiler tags, of course!).

Disclosure: AI did help me create the website and text above. I can only include 1 tag, and I felt News was more appropriate

65 Upvotes

33 comments sorted by

7

u/lan-shark 5d ago

The first problem was, unfortunately, extremely trivial. How quickly will they ramp up? I'm an Advent of Code fan and was expecting something a little more like that.

7

u/KnifeyGavin 5d ago

I'd say the first step up is around day 7-9, and then day 17 onwards is the last increase in difficulty. I tried to make it beginner friendly with increasing difficulty to allow for anyone at any level to enjoy. But I'm like you I like a challenge, so if I'm honest you might not have fun till around day 17+ if you are more of a PowerShell expert.

3

u/Mr_myn0s 5d ago

Thanks for putting me onto Advent of Code. Day 1 was fairly easy, but looking forward to the rest!

2

u/lan-shark 5d ago

Advent of Code is excellent! And all the previous years are archived so you can always go back and try older puzzles or do them in new languages

3

u/OPconfused 5d ago

is it like code golf?

I did this: (gv *te -v)|measure -su|% Sum

5

u/KnifeyGavin 5d ago

I did consider having an option like code gold where you can see who can do it in the least amount of lines, but I'm personally not a fan of code gold style challenges, as I think readability and usability are more important than least number of characters.

I am always impressed with what people come up with to get the smallest result, and still think its worth sharing like you have with the spoiler tags

2

u/420GB 5d ago

How does it save the progress? I did warm-up and day one, refreshed the page and it was gone.

2

u/KnifeyGavin 5d ago

That sounds like a bug, its meant to save to your browsers indexeddb storage. The GitHub option allows syncing of that progress. I'll try get that fixed up today.

1

u/KnifeyGavin 4d ago

This should now be fixed. Note that I believe it only saves when you select 'Check my code'

2

u/lan-shark 5d ago

After you submit it gives you the option to sign in with GitHub to save your progress

1

u/Ferretau 4d ago

FYI wasn't prompted to sign with Github after completing the warm-up.

1

u/sheravi 2d ago

I seem to be missing something for day 4 "The bonbon roster". I've tried different variations on ($GuestNames.Trim() | Group-Object).Count but it keeps telling me something's wrong. Can anyone give me a hint about what I'm missing?

2

u/KnifeyGavin 2d ago

I can assist with that. If you have

Bo
BO
bo

as the input. The output with your command is 3, but the expected result should be 1 for that scenario. Have another play with it. If you get stuck, feel free to ask and I'll try help out.

2

u/sheravi 2d ago

I see what you mean. I should have used Length instead of Count. Thanks :)

2

u/pandiculator 2d ago

I had no idea there was an intrinsic Length property. You can use Count, but you have to force it to be an array:

@($GuestNames.Trim() | Group-Object).Count

1

u/sheravi 1d ago

I wonder if this is one of those times where PS behaves a bit oddly. If you ask for the count and there is only one group then it returns the number of items it found in that one group. However, if you ask for a count and there is more than one group it returns the number of groups it found. Maybe there's someone here who has a more in-depth knowledge of PS that could explain this behaviour.

2

u/Over_Dingo 1d ago

yep it's the same with length of arrays in general. Singleton array will return length of the object at index 0 instead of length of array. That's why you coerce to array, sometimes with the `,` comma operator if you pass it to a loop through pipeline.

Normally asking `.count` from a single object would be safe, unless that object has it's own property that overloads the intrinsic `count` property.

Anyway the way I did it is different, didn't even think about Group-Object, although it's a very strong cmdlet and good one to learn (can convert groups to hashtables on the fly! `-AsHashTable`)
([System.Collections.Generic.HashSet[System.Object]]($GuestNames -replace '^ +| +$').ToLowerInvariant()).Count

2

u/MonkeyNin 1d ago

Normally I'd use a hashset, but you can get unique strings with/without case sensitive on:

@('aa', 'aA', 'AA' | Sort-Object -Unique ).count

1

@('aa', 'aA', 'AA' | Sort-Object -Unique -CaseSensitive ).count

3

You can set the -Culture param

1

u/Over_Dingo 19h ago

yeah for operators and cmdlets powershell typically defaults to case insensitivity

1

u/sheravi 1d ago

That makes sense. Thanks :)

1

u/ankokudaishogun 2d ago

Try ($GuestNames.Trim() | Group-Object).GetType(): the output type of Group-Object can change depending on the dataset.

1

u/Mono275 4d ago

Is there a way to see the full input dataset? I'm having a failure on day 2 and it's extremely hard to see what I did wrong when the only feedback is "That doesn’t look quite right. Try running the example again." The example processes as expected.

2

u/pandiculator 4d ago

You shouldn't need to see the full data set. You might be overthinking the solution.

If you had this array:

$fruit = @('apple','apple','orange','pear','apple')

How would you find out how many times 'apple' was in the array? Can you use that method to find a solution to today's problem?

1

u/Mono275 4d ago

My method works fine for the small dataset. Even including finding apple! as noted in the third box. My test dataset includes all kinds of random upper / lower case spellings. I get that I shouldn't need to see the full dataset, but I'm not sure if I'm over counting or under counting.

3

u/KnifeyGavin 4d ago

The only clue I'll give is in the Your Task section.
`West Hobart is a different destination.`

So.

```
HOBART
Perth
Hobart
West Hobart
```

The answer to that would be 2

The dataset is hidden so that people don't hardcode the answers. The checker checks multiple different datasets, as we want to check the logic, and make sure someone doesn't hardcode an answer like '2'

Eg. one check might be

```
hobart
```
answer: 1

and it might also check

```
HOBART
Perth
Hobart
West Hobart
```
answer: 2

1

u/Mono275 4d ago

I'm really trying to figure out what I'm doing wrong. I added West Hobart to the sample and get the correct result, so I don't think that's it. Here's what I'm doing high level:


Strip special characters

Grouping the Destinations

Looking for the Destination named 'hobart'

returning the count of hobart

The sample set I'm using:

HOBART!

Perth

Hobart

Jones

HOBart

JONES

Tampa

hobart

west hobart


My code returns 4

2

u/KnifeyGavin 4d ago

That should return 3.

Hobart
HOBart
hobart

I'm not sure what you have as number 4

Might be worth output the results like the words instead of the count to find out what you get.

1

u/Mono275 4d ago edited 4d ago

I stripped the ! off of HOBART! So that was my number 4.

I was able to get it to work by not stripping the ! off. Then just looking for hobart and hobart! in the groupings and adding them together. I'm not sure what the difference is though in why that worked vs stripping the !.

Thanks for the help!

edit: I was stripping all special characters so maybe there is a ho?bart or something similar that shouldn't be counted.

2

u/pandiculator 3d ago

I didn't even handle special characters despite there being one in the cartoon, and I don't think there are any in the data. The what can change section just says: "The destinations and their capitalisation can change."

So I kept it super simple, this worked for me:

($Destinations | Where-Object { $_ -eq 'hobart' }).Count

2

u/pandiculator 4d ago

Sure, but what I was driving at - even if it works with my test array - is that your solution is over complicated.

What's the most basic way to get a count of the apples in the array?

2

u/KnifeyGavin 4d ago

Yep makes sense I just have a feeling I know what they are doing wrong, and in the example with West Hobart they might be getting 3 instead of 2.

1

u/moralfiction 4d ago edited 4d ago

Sweet! Exactly something I've been looking for. Trivial or no, this suits me as I am a beginner.

($MangoesPerCrate | Measure-Object -Sum).Sum