#Advent of Code 2022 [May contain spoilers!]
1 messages Β· Page 2 of 1
this is what i would do || $stacks | gm | where {$_.membertype -eq "noteproperty"} | %{ New-Variable -name "Stack$($_.name)" -Value $stacks.$($_.name)}|| however, new-variable seemingly doesnt let one specifiy the type... And what comes out of it is of fixed size, so i cant add to it.. Any idea how to creat arraylists with this approach?
really weird that new-variable cant specify type, isnt it? shouldnt it be able to?
why would you do that?
that's going to be incredibly inconvenient to use
what kind of object would make your individual stacks really easy to access?
well i can just take one from $Stack2 and add it to $stack 4 then for exqmple
$item = $stack2[-1]
$stack2.remove($item)
$stack4.add($item)
what is this: ps $stacks that you can gm it to get a bunch of properties?
something like that, no?
and you can access $stack2 based on your input, how?
I know precisely how you can do it, I wouldn't consider it for a moment, it's going to be incredibly slow
or put differently. What possible benefit do you think you gain by having a bunch of variables instead of just some properties of an object?
"move 3 from 1 to 3"
split on " ", first is $origin stack, 2nd is $target stack, thrid is how often
$item = $stack$origin[-1]
$stack$origin.remove($item)
$stack$target.add($item)
something like this?
well no
fundamentally you cannot access variables like that
you could use Get-Variable, but why would you do that?
i mean it needs refinemaant, its just pseudo now, but shouldnt this work?
no
you fundamentally cannot do ps $var = 'stack' $value = 1 $var$value to access $stack1
$stack$origin.remove($item), I know that $stack$origin will not work as is. I would need to make it work
why?
what is $stacks?
you ran gm on it. Why can't you just directly use those properties you have?
a csv
because while you cannot do this: ps $var = 'stack' $value = 1 $var$value you can do this: ```ps
$object."$var$value"
no, it's not a CSV
it was a CSV
it's not a custom object with a bunch of properties
what do you get if you run ```ps
$stacks.1
now it won't quite work because it's a bunch of rows. You need to flatten it a bit
i might miss a significantly important piece of cusatomobject handling here π
perhaps there's another structure you can use where it's completely trivial to access named values
you could use your custom object, but you need to flatten it a bit
guess you mean hashtables?
well it'd be very fast to access, right?
and it's not much different from your current, you just swap New-Variable out for a new key in your hashtable perhaps
ok thanks, I will give it a try. but have to go now. Thanks, in any case, very helpfull as always!
gahh started late and my ||gridtraversal throws me into the gutter|| ill try again tomorrow
and i understand that ||djikstra or bfs|| is usable
If you have any old 2021 AoC code, this puzzle can be solved very similarly to ||2021 Day 15||
yea i do but they end around now. But i want to learn that way so iβll put on the thinking cap
I looked at yours after I'd done mine, I thought it particularly elegant π
Implementing something like ||BFS|| from scratch is definitely not in my wheelhouse and the solution from last year that I adapted mine from took a long time and I think I had adapted it from one of the C# solutions. But thankfully reading through my old code wasn't too bad and now I definitely understand it more having implemented it a second time.
My part 1 for today is done and I know what I need to do for part 2, but it's getting pretty late and I really shouldn't stay up to finish it.....which means I'm almost definitely staying up to finish it.
sipping coffee, reading pt1 description π
this would be much faster if people didn't keep making me do work
π
got another meeting in a few minutes, this is just not right
π
its day6 part 2, heres is my code
[char[]]$data = Get-Content .\day6\input6.txt
[char[]]$data = Get-Content .\day6\testinput6.txt
$length = 14
$length = $length - 1
$i = 0
do {
[char[]]$test = -join $data[$i..$length]
($test | group | select -expand count |select -Unique) -eq 1
$i++
$length++
} until (
$i -eq 10
)
$test is the current chararray, it groups by characters, selects the count per character (as unique) , i want it to return true only if it is exactly 1
not
1
2
4
``` or something
if you group on chars here: ```ps
$test | group
how many groups should you have for it to meet the uniqueness requirement?
ah, that is clever π
thanks a lot :d
ok, that just happened to bring this up here, not that its an issue for me here, im just curious, how would you adress this so that the last .count acts as the propertyname, not the method?
is that possible or would i need to use select count then?
is it possible with the .?
this, but "dotting" it instead of using select. possible?
you mean the first one that returns 13?
yes
is it possible to use the .count in some way so that it expands the property count, instead of invoking the count method
i dont, im just curious
ah cool, no afraid not. The .Count property on each value is masked by the .Count property on the array
you'd need something to enumerate the collection, whether that's Select-Object, or ForEach-Object or anything else
alright
this ```powershell
measure-command {
$length = 14
[char[]]$data = Get-Content .\day6\input6.txt
# [char[]]$data = Get-Content .\day6\testinput6.txt
Clear-Variable res
$end = $length - 1
$start = 0
do {
[char[]]$test = -join $data[$start..$end]
if (($test | Group-Object).count -eq $length ) {
$res = $end + 1
}
$start++
$end++
} until (
$res -ne $null
)
$res | out-file .\day6\result2_day6.txt
get-content .\day6\result2_day6.txt | Set-Clipboard
}
is way better then what i had before
I knew it wouldnt scale, but i wanted to birth this abomination anyway :
measure-command {
[char[]]$data = Get-Content .\day6\input6.txt
# [char[]]$data = Get-Content .\day6\testinput6.txt -raw
Remove-Variable 1stBeforecurrent, 2ndBeforecurrent, 3rdBeforecurrent, current, i -ErrorAction SilentlyContinue
$i = 0
$res = foreach ($d in $data) {
$i++
$current = $d
if ( ($1stBeforecurrent -ne $null) -and ($2ndBeforecurrent -ne $null) -and ($3rdBeforecurrent -ne $null)) {
if ($( (Compare-Object $(Compare-Object $(Compare-Object $current $1stBeforecurrent -IncludeEqual ).inputobject $2ndBeforecurrent -IncludeEqual ).inputobject $3rdBeforecurrent -IncludeEqual).inputobject.count) -eq 4) {
$i
break
}
}
$3rdBeforecurrent = $2ndBeforecurrent
$2ndBeforecurrent = $1stBeforecurrent
$1stBeforecurrent = $current
}
$res | out-file .\day6\result1_day6.txt
get-content .\day6\result1_day6.txt | Set-Clipboard
}
``` π
sigh crazy day. No time to do todays today. No time to do tomorrows tomorrow either. Hey ho.
i feel you
And im stuck on yesterdays and started to look at todays and when i saw it i remembered last years ||{[({{][]}]]]}|| and just uuuggh
lol yes indeed
no it seems my brain wont work
@junior light wow i like you day13 it explains alot that i was missing π
i was trying to add the brackets with a ||queue|| and i did some iffy ||regex|| and got part1 test work but when ran against the whole it just blew up
technically those packet strings are ||all valid JSON|| such that you could use ||ConvertFrom-Json|| to parse them. But it's a lot of nesting and I didn't really feel like making a recursive solution.
yea well its starting to take way to long time for me now.
i tried to just replace || [],|| with ||blank|| and it works quite well but i cannot compare the || lists|| but it did work on the test, i guess they didn't include advanced ones there
There's at least one example in the real input that contains an edge case the sample didn't cover. Lemme see if I can remember what it was and make a little extra sample that would trigger it.
thanks
[[]]
[[[1,2,3]]]
[[9]]
[[10]]
Try those in addition to flipped versions. The first one is sort of covered by the second to last sample. But there were also no samples that had numbers over 9.
Technically, the puzzle text didn't specify there was any limit on the numbers. But I verified at least on my puzzle input that there were no numbers over 10.
But the fact that 10 was there at all screwed up my initial plan a bit until I found my workaround.
ok, || i saw you 10 replaced to :||
yep
thanks for the input, i will tinker on π
whine stupid work getting in the way of my Day 14 fun. I got part 1 done last night but I haven't had a chance to start part 2 yet.
but it renders nicely so i dont know what i have missed :/
and it runs waaaay faster in pwsh5 then 7 for some reason
I'm now days behind π¦
Don't feel too bad Chris, I'm a week behind π
π Tempted to just let it slide, see if I can be bothered tomorrow π
Probably gonna ignore for another week and then do all of them during the 24th-25th π
haha brave π
lucky you to be able to do all in two days. π
The joys of being childless π
π also that, but have the knowhow to solve them in that timespan
i am just starting on Day 1, i started yesterday actually and i'm not making much progress, is it still ok to ask for help if i'm 2 weeks behind?
I've tried a few things and I just keep getting stuck. Here's what I have atm, that doesn't work.
|| [array]$file = (get-content 'C:\Users\m03324\OneDrive - MISO Energy\Documents\Powershell\Advent of Code\2022\Day1\elfcalories.txt' -Raw) -split "`n"
[array]$file | foreach-object [int]$_
[array]$elves = foreach-object [array]$file -split "`n"
Select-Object $elves -first 1||
it doesn't like line 5
line 5 isn't valid code, you need to reconsider that one
ForEach-Object will need a script block to run the code you're attempting to give it, but practically the code you're giving it is a bit confused
yeah i switched around line 1 to ||split by "'nn" so that it first divides into the groups and then into the lines|| but i'm still not sure that's quite right
that's the approach I took to break it into per-elf values
ok i made it further this time
||[array]$file = (get-content 'C:\Users\m03324\OneDrive - MISO Energy\Documents\Powershell\Advent of Code\2022\Day1\elfcalories.txt' -Raw) -split "nn"
[array]$file | foreach-object [int]$_
#[array]$elves = $file -split "`n"
1..$file.count | foreach-object {
[int[]]$elves = $file[$_n] -split "`n"
$file[$_n]
$elves|foreach-object {
$elf = 0
$elf = $elf + $_
}
$elf
}||
i got the first part, thanks for the help!
||``[array]$file = (get-content 'C:\Users\m03324\OneDrive - MISO Energy\Documents\Powershell\Advent of Code\2022\Day1\elfcalories.txt' -Raw) -split "nn"
$max=0
0..$file.count | foreach-object {
[int[]]$elves = $file[$_] -split "`n"
$elf = 0
$elves|foreach-object {
$elf = $elf + $_
}
if ($elf -gt $max)
{
$max=$elf
}
}
$max``||
yay found some time... day 14... not quite as far behind
code is probably a horrible mess... I started it on day 13, but it has been split into 10 minutes here, 10 minutes there: https://github.com/indented-automation/AoC/tree/master/2022/13
heh spotting extraneous statements in it as I look again. Best just keep that closed
I finished Day 14 about 5 min before Day 15 dropped. It's still messier than I'd like. But oh well. Managed to finish Part 1 of Day 15, but can't get away from work stuff long enough to keep going to part 2.
beyond the first couple of sentences, I haven't really looked much at 14. I might regret looking tomorrow π
see how the day goes... next week might be better since I'm on holiday
right, maybe I can have a look at day 14 now. I bet I regret this...
Working on Day 2 now, at this rate I should be done by Easter π
did both parts 14 this morning and part 1 of 15, just finishing 15
Ok, made it to part 3
Here's what I have so far
||[array]$file = (get-content 'C:\Users\m03324\OneDrive - MISO Energy\Documents\Powershell\Advent of Code\2022\Day3\rucksacks.txt') -split "n"
foreach($line in $file)
{
$side1 = $line.substring(0,$line.length/2)
$side2 = $line.substring($line.length/2)
$side1
$side2
$same = Compare-object -ReferenceObject $side1 -DifferenceObject $side2 -IncludeEqual -ExcludeDifferent
$same
}`||
Part 3? There's only 2 daily puzzles?
No worries, I'm not that much further π
Obviously, my ||compare-object|| doesn't work the way i want it to
You probably want to split the strings into [char[]] π
$side1 = $line.Substring(0,$line.length/2).ToCharArray()
and the same for the other "compartment" of the rucksack of course
thanks, i'll try it!
is musing how to make day 15 pt 2 fast enough
Dammit, now I have to check it out π
I did some optimisation for pt1, that takes 14ms
but it is no where near enough to deal with pt2
ugh, spatial stuff, I hate dimensions xD
at least it's only 2 of them so far
fairly sure day 19 last year was almost the end of me
Ok I got Day 3 part 1, but i'm not happy with part of my solution
||``[array]$file = (get-content 'C:\Users\m03324\OneDrive - MISO Energy\Documents\Powershell\Advent of Code\2022\Day3\rucksacks.txt') -split "`n"
$total=0
foreach($line in $file)
{
$side1 = @($line.substring(0,$line.length/2).ToCharArray())
$side2 = @($line.substring($line.length/2).ToCharArray())
$same = Compare-object -ReferenceObject $side1 -DifferenceObject $side2 -IncludeEqual -ExcludeDifferent -PassThru -CaseSensitive
$same[0]
$count=[int]$same[0]
$count
if ($same[0] -cmatch "[A-Z]")
{
$total =$total+[int]$same[0]-38
}
else {
$total =$total+[int]$same[0]-96
}
$total
}
#capitals -38 smalls -96||`
Why is ||my compare-object returning more than 1 value?||
it's only sometimes returning more than one value, where the character is really present more than once in each side
so for instance, given a couple of my inputs ```ps
LMhtCSSftfTzdCdMhSCd
MsQGQbGnbGQQMQggDNgR
The comparison between the two arrays identifies that `M` appears twice in both sides
ok, is there any kind of way to make it only pull out unique matches?\
it's a bit of a garbage in / garbage out problem. You would either need to do that before asking for the comparison, or after, or use some other method entirely to do the comparison
ok, thanks! i appreciate all the help!
random fyi, you don't need the -split on your Get-Content. It reads line-by-line by default. I suspect you know this and just weren't particularly looking at it π
did you do 15 pt 2 @sly reef ? If so, wondering if you have any hints π Otherwise I need to exercise me brain more than today will permit I think
hint: Group-Object and [HashSet[string]] (or [HashSet[char]]) are your friends when looking for only distinct values π
For native PowerShell comparisons: remember everything is case-insensitive by default - remember to add the c modifier to comparisons, eg. -ceq, -ccontains etc.
I've got a day 15 part 2 committed that works but slow. How slow is highly dependent on where your answer happens to be within the y-axis range. Closer to 4000000 will be faster. Mine was around 3400000 and took about 2 min to run. Lower will take longer because I it starts checking at the end instead of the beginning. Use -Verbose to see progress.
I've since looked at some other solutions on the megathread that are way smarter (and faster) than my method. Makes me want to scrap my code and port their implementation just to learn.
I've deferred it until some time beyond today π I have an inkling of a way, but it needs percolate for a while (this may or may not result in an actual idea)
had a brief look at day 16 and called my efforts for the day at that point. 1.5 days is enough catching up for today
Yeah, I spent about an hour pondering Day 16 and decided it's beyond me for the time I have. This is about when that starts happening every year. So I'll start porting other solutions as I have time.
yeah, no bad thing there. This is around the point when things start needing far too much of a day to resolve. I was happy enough that I did 14 in a timely manner even if it's not especially fast. "Fast enough" applies.
for sure
todays first thought was "isn't this just weighted paths through a graph"
but you can visit nodes multiple times and the weights change
yeah, that's about when I stopped thinking I was going to attempt that today π
pretty much
Ok, day 3, part 2
Here's what I've got
||``[array]$file = (get-content 'C:\Users\m03324\OneDrive - MISO Energy\Documents\Powershell\Advent of Code\2022\Day3\rucksacks.txt') -split "`n"
$total = 0
$group = @()
foreach ($line in $file) {
$side1 = @($line.substring(0, $line.length / 2).ToCharArray())
$side2 = @($line.substring($line.length / 2).ToCharArray())
$same = Compare-object -ReferenceObject $side1 -DifferenceObject $side2 -IncludeEqual -ExcludeDifferent -PassThru -CaseSensitive
if ($same[0] -cmatch "[A-Z]") {
$total = $total + [int]$same[0] - 38
}
else {
$total = $total + [int]$same[0] - 96
}
$group += $line
if ($group.length -eq 3) {
$elf1 = @($group[0].ToCharArray())
$elf2 = @($group[1].ToCharArray())
$elf3 = @($group[2].ToCharArray())
$badgecompare = Compare-object -ReferenceObject $elf1 -DifferenceObject $elf2 -IncludeEqual -ExcludeDifferent -PassThru -CaseSensitive
$badge = Compare-object -ReferenceObject $elf3 -DifferenceObject $badgecompare-IncludeEqual -ExcludeDifferent -PassThru -CaseSensitive
if ($badge[0] -cmatch "[A-Z]") {
$badgetotal = $badgetotal + [int]$badge[0] - 38
}
else {
$badgetotal = $badgetotal + [int]$badge[0] - 96
}
$group = @()
}
}
$total
$badgetotal
``||
I'm good up to line 28, where the ||$badgetotal compare|| isn't returning anything
i don't think i'm probably spoiling anybody at this point, but i thought better safe than sorry
nono, it's all good, just momentary forgetfulness on my part
my discord skills are only marginally better than my powershell skills π
oh you won't like this
you're missing a space
-DifferenceObject $badgecompare-IncludeEqual
fresh eyes are always helpful
that's a nasty little bug since it doesn't complain about syntax errors or anything, just an inexplicable null array
yeah it would have been nice if it had given me a heads up about that, but this has happened to me so many times over the years in so many programming languages, i just have to laugh
even editing it to fix I was thinking "hmm no that can't be..."
aaaand now it works
yep, same answer as mine
||https://github.com/indented-automation/AoC/tree/master/2022/03|| is mine for 3, I went with ||Intersect|| instead of ||Compare-Object||. Not quite as PowerShelly
I had skimmed the answers other people put in reddit to kind of get me started, and I saw that, and looked it up, but it was confusing, so i went this way instead
yeah, right thing to do
no, i havent had time to try. i did some basic design on part 1 but thats it. im afraid
Had to take a week off and finally done Day 7. So happy π Took the best part of today though so I'm beginning to think I won't make it until the end.
heh I've kind of given up, busy days at work and now I'm on holiday. The catch-up required is daunting. Maybe in January π
Yeah, I have a feeling these will keep me going until December next year π I'm going to take a break for the rest of the day as my brain is mush but tomorrow will start the one where you need to find a place for a treehouse. I seem to have more problems finding a way to feed the data into memory than actually doing the problem-solving it seems.
well have a hint for tomorrow. Finding a tree house is ||path finding||, and there are a few really ||well known algorithms|| for this which you can leverage. I may have got stuck for 2 hours on that one by failing to properly read a couple of the instructions.
Interesting - I just read your hints. At first I was thinking I was going to|| feed the text in as a 2d array and then do a for loop across each item, checking up down left and right.|| I see now how many trees can be seen from outside the grid though so I'm thinking ||go round from the border and work your way in, if you hit something that's higher, go to the next location on the border||
Is the outside the grid bit the bit you overlooked?
nope, much more trivial than that
I misread the values for ||S and E||, so my result was consistently out by exactly 2 in the most frustrating way π
Ahhh
otherwise, since I've done ||pathing|| before in AoC, it would have been a 30 minute thing to finish π
So I'm thinking this:
||A custom object which stores the x and y coordinates of the tree but also another bool which reflect if the tree has been seen yet. I then go round the border of the grid and work my way in we hit a tree that is taller than the last. If we hit the tree we mark the $_.Seen to $True and then go to the next tree on the border and start again||
it'll be slow
I know this because last year... The well known algorithms visit ||fewer nodes|| you see. Whereas your approach, like mine last year, ||will need you to repeat the process n times to refine the path||.
Hm, I can't really think of any other way than ||going around the edge and working my way inwards which means you do one sweep from each starting node. Working down from the top row, working right from the left row, etc.|| That way you check everything once. π
see how you get on, if you get stuck just yell and I'll hint a bit more π
||I suppose the problem is the 2nd column and the -2 column when the side keeps checking them again and again||
Ok thanks, I'll think about it tonight and try and write something tomorrow. I'm also on leave now
I can't personally see ||how pathfinding fits into this as I'm not looking for the shortest path anywhere. I'm just trying to find which trees are in view. Is the second part to do with the pathfinding?||
hm maybe I'm thinking about the wrong one
The one I'm on is where there's 5x5 trees all of different heights and we have to determine which are visible from the perimeter (a taller tree in the way will block it).
So ||I go round the perimiter and work my way inwards to the centre but not "path finding" as such||
ah no, you're completely right... lost track π
No worries, I thought I had missed some cool trick!
hah no... I had skipped ahead to day 12
Day 8 and I am already beginning to wonder if I'm near my limit now. π My brain is starting to melt
I did crazy things for day 8 π
How did you approach it? I am thinking ||counting the perimeter and then essentially spiralling my way around inwards, checking the outside of each tree.||
oh hey, I did that for my first revisions... had a few for this particular day π
It will take me most of the day to do one so by that point I'll probably move on quite quick to the next one π
you can have a look at my variant that draws progress when you're done. It's amusing, but... well I have a third variant too π
although only of part 1, I didn't bother upgrading part 2
Once I'm done I'll have a check! If I don't do it myself first I'll end up just ripping yours off.
it's not the best for sure. I stepped away for it once I got the right answer or I'd have never stopped fiddling π
Hm ok. So this is a bit of a trick question...
From the example:
The left-middle 5 is visible, but only from the right.
And then it goes on to say how many trees are visible from outside the grid?
So I coded it all so if it was visible from any angle it counts π’
yep, which is the correct thing to do, but only for N, S, E, and W, cardinal points (if that's the right term)
I think it shouldn't be hard to change ||by adding breaks in if it marks a tree visible but I spent ages trying to figure out why it wasn't working matching hte number in the test data||
visible from NE doesn't count, so no diagonals or angles to deal with
Yeah that's all good ||it's pretty much just four for loops which work there way into the centre comparing against the previous tree. Now I just gotta add breaks in||
Hang on... Have I misunderstood completely...
If you're scanning from left to right the following:
1 0 3
Would you expect the 3 to also flag up because it's higher than the highest tree you've found so far?
I'm stopping when I find a tree that's not visible:
Would you expect the 3 to also flag up because it's higher than the highest tree you've found so far?
Yes, exactly
Oh man.
LOL
This is killing me.
The problem is, I can't seem to figure out a way to wrap my four scans into a method so every change means I have to change four loops.
if it helps at all, ||I ended up with 4 loops||
my initial attempts had it ||spiral||. I eventually ||dropped that||, it requires ||too many iterations||. Many of the solutions ||look at each tree, then evaluate all between it and the edge in every direction||
I didn't like that ||but it works|| approach. I (and this is the real spoiler), ||evaluated every tree from each direction in turn|| hence ||4 loops||
It sounds like you've done what I've done. ||I am working on the basis that every tree is not visible unless proven otherwise and then I am scanning from the left to right, each row, and then right to left, and then up to down, etc. Seems to work but now I need to change the comparison against a "HighestTreeSofar" variable||
yep, that's exactly what I ended up with. I maintained the ||"visible from"|| for each ||direction separately as a property on each tree|| so that I didn't have to look beyond ||it's nearest neighbours||
Oh that's interesting. I hadn't considered that!
doing all that meant that pt 1 ran in 128ms in the end which was about as fast as I could possibly get
||```powershell
function Scan-Trees {
param (
[Object[,]]$Data
)
# Go from each tree on the top row, down to the middle:
$HighestSoFar = $Data[]
for ($x = 1; $x -lt $X_Length - 1; $x++) {
for ($y = 1; $y -le $Centre; $y++) {
if ($Data[($y-1),$x].Height -lt $Data[$y,$x].Height) {
$Data[$y,$x].Visible = $True
}
else {
break
}
}
}
# Go from each tree on the bottom row, up to the middle:
for ($x = 1; $x -lt $X_Length; $x++) {
for ($y = $Y_Length - 2; $y -ge $Centre; $y--) {
if ($Data[($y+1),$x].Height -lt $Data[$y,$x].Height) {
$Data[$y,$x].Visible = $True
}
else {
break
}
}
}
# Go from each tree on the left column, right to the middle:
for ($y = 1; $y -lt $Y_Length; $y++) {
for ($x = 1; $x -le $Centre; $x++) {
if ($Data[$y,($x-1)].Height -lt $Data[$y,$x].Height) {
$Data[$y,$x].Visible = $True
}
else {
break
}
}
}
# Go from each tree on the right column, left to the middle:
for ($y = 1; $y -lt $Y_Length; $y++) {
for ($x = $X_Length - 2; $x -ge $Centre; $x--) {
if ($Data[$y,($x+1)].Height -lt $Data[$y,$x].Height){
$Data[$y, $x].Visible = $True
}
else {
break
}
}
}
Write-Trees $Data
}
||
How it looks at the moment - I've just broken my backspace so trying to fix that before adding the changes π
yeah, very similar. I didn't even bother ||merging those loops into one|| despite the repetition π
Done it! I feel like I could've done it hours ago if I didn't break my preferred keyboard and have a throbbing headache. To be fair I did have a nap and come back to it but even after that I ended up tying myself in knots for another hour or two! ||https://github.com/DarylGraves/AdventOfCode2022/blob/main/Day_08/Day_08_Part_1.ps1||
Whaaat! Now the elves have decided they don't want their tree house hidden, they want it to overlook other trees! π
Second part was easier. Always seems to be easier once you've laid down the foundations
|| $rucksacks = Get-Content -Path "C:\Users\monst\Documents\Advent22-3.csv"
$UpperAZ = char[]
$UpperAlphabet = -join $UpperAZ
$LowerAZ = char[]
$LowerAlphabet = -join $LowerAZ
[System.Collections.ArrayList]$MatchedCharacter = @()
$SplitLength = 0
for ($i = 0; $i -lt $rucksacks.length; $i++) {
$TotalLength = $rucksacks[$i].length
$SplitLength = ($TotalLength / 2)
$FirstSack = $rucksacks[$i].Substring(0, $SplitLength)
$FirstCharArray = [char[]] $FirstSack
$SecondSack = $rucksacks[$i].Substring($SplitLength)
$SecondCharArray = [char[]] $SecondSack
foreach($char in $FirstCharArray) {
if ($SecondCharArray -ccontains $char) {
$MatchedCharacter.Add($char)
}
}
}
$UniqueArray = $MatchedCharacter | Select-Object -Unique
$PriorityTotal = 0
ForEach($char in $UniqueArray) {
if ($UpperAZ -ccontains $char) {
$char
$Priority = $UpperAlphabet.IndexOf($char)+27
$Priority
$PriorityTotal += $Priority
} elseif ($LowerAZ -ccontains $char) {
$char
$Priority = $LowerAlphabet.IndexOf($char)+1
$Priority
$PriorityTotal += $Priority
}
}
Write-Host "Total priority is $PriorityTotal" ||
Been banging my head against day 3part 1 for a couple hours, not sure what i'm doing wrong here. It's telling me im too low when I filter just the unique values out
I don't fully get why you're doing $Matched Character | Select-Object - Unique?
You found all the shared items but if there's 2 seperate lines with the same char, you're removing one of them I think?
@sly reef Good solution for day 1. I'm just learning to program and I was superhardstuck on day 1 . After I understood what you had done I was quite suprised on how it could be solved
Thatβs what I thought, but the answer was still wrong when I was doing without that. And looking at other solutions, that seemed to be only thing I was missing.
How are you getting on with it? Sorry I've been out Christmas shopping all day π
Havenβt been able to touch it yet. Day job and stuff
@hollow perch apparently I didn't account for when some strings have more than two similar letters and was adding more priority in. Woops
Fixed it with a single "break" lol
Ah nice one! Congrats on sorting it!
@azure grail thanks, alot of these is about parsing the input.
@short junco day15 part1 i think i made it super slow by ||adding all # to the area of the sensor||
I can see that you have a different approach
ah yeah, that's where I stopped
In the test it runs superfast
but now its just struggling to fill them
i have a ton of loops doing the lifting
i have to refactor it
Having a look at your code i see that you check if ||sensors area overlap and add those ranges? ||
yeah, for me I think it reduced it to a single range
Im doing an Invoke-Restmethod trying to catch this specific value, dont find a proper way
$MapData = Invoke-RestMethod -Uri "https://kz-rush.ru/en/maps/cs16/zs_60units"
foreach ($Difficulty in ($MapData.Split("`n"))) {
}
Any ideas how to grab it? Its the only site providing how hard a specific map is π
<span class='mapsinfo-subheader'>Difficulty</span> this row seems to always be the same so I would like to get there and then take the next row and only that. Somehow.
you sure this is in the right place? π