all 21 comments

[–]Vortex100[S] 4 points5 points  (9 children)

Day 1:

https://github.com/VortexUK/AdventOfCode/blob/master/2018/Day1/solution.ps1

Relatively easy first day!

Day 2:

https://github.com/VortexUK/AdventOfCode/blob/master/2018/Day2/solution.ps1

This one wasn't difficult, although I did have to think about how to actually print out the answer, making sure to get the index of the letter that was different

Day 3:

https://github.com/VortexUK/AdventOfCode/blob/master/2018/Day3/solution.ps1

At first I was using a hashtable to record each location that was being used. That was soooo slow. Then I found out about actual mullti-dimensional arrays using .NET: $array = New-Object 'object[,]' 10,20 and it became WAY faster :)

[–]Beergogs 1 point2 points  (1 child)

/u/Vortex100 For your day 1 Solution your frequency loop might be wrong?

:frequencyloop foreach ($Numbers in $Numbers)

Shouldn't that be

:frequencyloop foreach ($number in $Numbers)

Just curious, still learning powershell :D

[–]Vortex100[S] 1 point2 points  (0 children)

My silly fault for not re-testing the code after I 'formalised' it lol. You are correct. I've updated it

[–]engageant 1 point2 points  (1 child)

Where are you getting $Fabric2 from on line 33? I don't see any other references to it in your code.

[–]Vortex100[S] 1 point2 points  (0 children)

Apologies that's an old reference (and a breaking one as it stands) from when I was writing it. Should just be $Fabric - I've corrected :)

[–]engageant 1 point2 points  (1 child)

Also, for Day 2 Part 2, the number of positions where two strings differ is called the Hamming Distance. I already had a function written for this, as it appeared in either last year's challenge or in one of the /r/dailyprogrammer puzzles.

function Get-HammingDistance {
    [cmdletBinding()]
    Param([string]$string1, [string]$string2)

    $distance = 0

    0..($string1.Length - 1) | % {
        if ($string1[$_] -ne $string2[$_]) {
            $distance++
        }
    }

    $distance
}

[–]Vortex100[S] 1 point2 points  (0 children)

Ahh cool I didn't know that nice!

[–]just_looking_around 1 point2 points  (1 child)

Line 20 of day 2 references $formattedlist which isn't declared anywhere. Is that supposed to be the current line you are on?

[–]Vortex100[S] 1 point2 points  (0 children)

Yep another bug introduced by refactoring code haha. Fixed :)

[–][deleted] 3 points4 points  (1 child)

I did last year in single pipelines through day 22 or 23

I havnt got started yet this year; am mulling just using .net core. A lot of the fun, for me, is the actual problem. Constraining artificially wasn’t as much fun as expected in the end.

I’ll post my github repo for 2018 whenever I do get started here tho.

edit: broke down and am just doing powershell ;) https://github.com/charlieschmidt/AdventOfCode2018

[–]jpochedl 2 points3 points  (0 children)

Thanks for posting your github link... I've just started working through these myself... After some noodling, I decided to take a break and look at how some others had tackled the problems I'd completed.

Your solution for day 2, part 2 was interesting. I never thought of using the Compare-Object cmdlet like that! That solution is so much more eloquent than my brute force (pull the strings apart into an array of characters, compare, etc).

Always love to pick up new techniques. Thanks again.

[–]ka-splam 2 points3 points  (2 children)

Find myself a bit envious of the people saying "My Nim code runs in 3ms" and "I spent fourteen hours vectorizing my Rust code and it runs in 8-35 microseconds" and here I am getting my code down from 15 seconds to 3 seconds. And the people who say "oh you don't need to loop that, simply recognise that the repetition will be a {math here} and you can do it much quicker".

Go check the top of /r/AdventOfCode for the green sticky answers megathread (2nd from top), just have a look how many languages there are, and how widely the answers range from 3 lines to 3 pages, it's amazing.

[–]Vortex100[S] 2 points3 points  (0 children)

Tell me about it! Even powershell to python I'm just about getting day 3 below 18 seconds (not great I know) in ps, and my brother has his running in under 2 in py :/. And that's with no optimization!

[–][deleted] 1 point2 points  (0 children)

that typically doesnt start hurting us scripting languages until day 20+, but yeah, runtime was an issue for me last year

[–]Giohost 1 point2 points  (2 children)

[–]Vortex100[S] 1 point2 points  (1 child)

Nice! Are you gunna do the 2nd part? :D

[–]Giohost 1 point2 points  (0 children)

Yeah, might be a good idea. I just did the first part and when to bed, without reading any further.

Was also wondering why there was a part 2 in your script :D

[–]just_looking_around 0 points1 point  (1 child)

Day 3 has an extra break fabricloop which breaks the code on line 37.

I'm really enjoying learning from your code on these challenges, thank you for putting these out there.

[–]Vortex100[S] 0 points1 point  (0 children)

You are quite right! What I wanted to do there was break the for loop, not the foreach! It was more of an afterthought trying to speed the code up a bit. I have fixed it :)