#Advent of Code 2022 [May contain spoilers!]

1 messages Β· Page 2 of 1

paper flare
#

now id make an array for each stack and then i should be able to add and remove from em, shouldnt i?

#

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?

short junco
#

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?

paper flare
#

well i can just take one from $Stack2 and add it to $stack 4 then for exqmple

short junco
#

yep, sure

#

how are you going to do that in code?

paper flare
#

$item = $stack2[-1]
$stack2.remove($item)
$stack4.add($item)

short junco
#

what is this: ps $stacks that you can gm it to get a bunch of properties?

paper flare
#

something like that, no?

short junco
#

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?

paper flare
#

"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?

short junco
#

well no

#

fundamentally you cannot access variables like that

#

you could use Get-Variable, but why would you do that?

paper flare
#

i mean it needs refinemaant, its just pseudo now, but shouldnt this work?

short junco
#

no

#

you fundamentally cannot do ps $var = 'stack' $value = 1 $var$value to access $stack1

paper flare
#

$stack$origin.remove($item), I know that $stack$origin will not work as is. I would need to make it work

short junco
#

why?

#

what is $stacks?

#

you ran gm on it. Why can't you just directly use those properties you have?

paper flare
short junco
#

because while you cannot do this: ps $var = 'stack' $value = 1 $var$value you can do this: ```ps
$object."$var$value"

short junco
#

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

paper flare
#

yeah that works

#

of course

#

but how can i add and remove from that?

short junco
#

now it won't quite work because it's a bunch of rows. You need to flatten it a bit

paper flare
#

i might miss a significantly important piece of cusatomobject handling here πŸ˜„

short junco
#

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

paper flare
#

guess you mean hashtables?

short junco
#

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

paper flare
#

ok thanks, I will give it a try. but have to go now. Thanks, in any case, very helpfull as always!

sly reef
#

gahh started late and my ||gridtraversal throws me into the gutter|| ill try again tomorrow

#

and i understand that ||djikstra or bfs|| is usable

junior light
#

If you have any old 2021 AoC code, this puzzle can be solved very similarly to ||2021 Day 15||

sly reef
#

yea i do but they end around now. But i want to learn that way so i’ll put on the thinking cap

short junco
junior light
#

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.

short junco
#

sipping coffee, reading pt1 description πŸ™‚

junior light
#

yay, done

#

sleepy time

short junco
#

this would be much faster if people didn't keep making me do work

sly reef
#

πŸ˜„

short junco
#

got another meeting in a few minutes, this is just not right

sly reef
#

call in care of sick children

#

and bail

short junco
#

πŸ˜„

paper flare
#

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
short junco
#

if you group on chars here: ```ps
$test | group

#

how many groups should you have for it to meet the uniqueness requirement?

paper flare
#

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?

short junco
#

what's wrong with your middle one?

#
 ('a', 'b', 'c' | Group-Object).Count
paper flare
#

you mean the first one that returns 13?

short junco
#

yes

paper flare
#

is it possible to use the .count in some way so that it expands the property count, instead of invoking the count method

short junco
#

oic

#

why would you need to?

paper flare
#

i dont, im just curious

short junco
#

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

paper flare
#

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
}
``` πŸ˜„
short junco
#

sigh crazy day. No time to do todays today. No time to do tomorrows tomorrow either. Hey ho.

sly reef
#

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

short junco
#

lol yes indeed

sly reef
#

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

junior light
#

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.

sly reef
#

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

junior light
#

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.

sly reef
#

thanks

junior light
#
[[]]
[[[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.

sly reef
#

ok, || i saw you 10 replaced to :||

junior light
#

yep

sly reef
#

thanks for the input, i will tinker on πŸ™‚

junior light
#

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.

sly reef
#

Im preparing to give up

#

πŸ™‚

sly reef
#

well i managed todays part1 quite fast

#

but part2 i have some missmatch

sly reef
#

but it renders nicely so i dont know what i have missed :/

#

and it runs waaaay faster in pwsh5 then 7 for some reason

short junco
#

I'm now days behind 😦

tired swift
#

Don't feel too bad Chris, I'm a week behind πŸ˜›

short junco
#

πŸ˜„ Tempted to just let it slide, see if I can be bothered tomorrow πŸ™‚

tired swift
#

Probably gonna ignore for another week and then do all of them during the 24th-25th πŸ˜„

short junco
#

haha brave πŸ™‚

sly reef
#

lucky you to be able to do all in two days. πŸ˜›

tired swift
#

The joys of being childless πŸ˜‚

sly reef
#

πŸ˜‚ also that, but have the knowhow to solve them in that timespan

digital cipher
#

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

short junco
#

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

digital cipher
#

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

short junco
#

that's the approach I took to break it into per-elf values

digital cipher
#

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
}||

digital cipher
#

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``||

short junco
#

yay found some time... day 14... not quite as far behind

short junco
#

heh spotting extraneous statements in it as I look again. Best just keep that closed

junior light
#

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.

short junco
#

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

short junco
#

right, maybe I can have a look at day 14 now. I bet I regret this...

digital cipher
#

Working on Day 2 now, at this rate I should be done by Easter πŸ˜„

short junco
#

did both parts 14 this morning and part 1 of 15, just finishing 15

digital cipher
#

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

}`||

tired swift
#

Part 3? There's only 2 daily puzzles?

digital cipher
#

Sorry, Day 3

#

I'm realllly behind

tired swift
#

No worries, I'm not that much further πŸ˜…

digital cipher
#

Obviously, my ||compare-object|| doesn't work the way i want it to

tired swift
#

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

digital cipher
#

thanks, i'll try it!

short junco
#

is musing how to make day 15 pt 2 fast enough

tired swift
#

Dammit, now I have to check it out πŸ˜›

short junco
#

I did some optimisation for pt1, that takes 14ms

#

but it is no where near enough to deal with pt2

tired swift
#

ugh, spatial stuff, I hate dimensions xD

short junco
#

at least it's only 2 of them so far

tired swift
#

True πŸ˜…

#

And no Euclidian geometry (yet...)

short junco
#

fairly sure day 19 last year was almost the end of me

digital cipher
#

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?||

short junco
#

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
digital cipher
#

ok, is there any kind of way to make it only pull out unique matches?\

short junco
#

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

digital cipher
#

ok, thanks! i appreciate all the help!

short junco
#

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

tired swift
#

For native PowerShell comparisons: remember everything is case-insensitive by default - remember to add the c modifier to comparisons, eg. -ceq, -ccontains etc.

junior light
# short junco _is musing how to make day 15 pt 2 fast enough_

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.

short junco
#

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

junior light
#

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.

short junco
#

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.

junior light
#

for sure

short junco
#

todays first thought was "isn't this just weighted paths through a graph"

junior light
#

but you can visit nodes multiple times and the weights change

short junco
#

yeah, that's about when I stopped thinking I was going to attempt that today πŸ˜„

junior light
#

pretty much

digital cipher
#

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

short junco
#

you know you can do multi-line blocks/

#

oh but it won't spoiler, nm

digital cipher
#

i don't think i'm probably spoiling anybody at this point, but i thought better safe than sorry

short junco
#

nono, it's all good, just momentary forgetfulness on my part

digital cipher
#

my discord skills are only marginally better than my powershell skills πŸ™‚

short junco
#

oh you won't like this

#

you're missing a space

#
-DifferenceObject $badgecompare-IncludeEqual
digital cipher
#

fresh eyes are always helpful

short junco
#

that's a nasty little bug since it doesn't complain about syntax errors or anything, just an inexplicable null array

digital cipher
#

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

short junco
#

even editing it to fix I was thinking "hmm no that can't be..."

digital cipher
#

aaaand now it works

short junco
#

yep, same answer as mine

digital cipher
#

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

short junco
#

yeah, right thing to do

sly reef
hollow perch
#

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.

short junco
#

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 πŸ˜„

hollow perch
#

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.

short junco
#

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.

hollow perch
#

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?

short junco
#

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 πŸ™‚

hollow perch
#

Ahhh

short junco
#

otherwise, since I've done ||pathing|| before in AoC, it would have been a 30 minute thing to finish πŸ˜„

hollow perch
#

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||

short junco
#

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||.

hollow perch
#

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. πŸ˜•

short junco
#

see how you get on, if you get stuck just yell and I'll hint a bit more πŸ˜„

hollow perch
#

||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

hollow perch
#

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?||

short junco
#

hm maybe I'm thinking about the wrong one

hollow perch
#

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||

short junco
#

ah no, you're completely right... lost track πŸ™‚

hollow perch
#

No worries, I thought I had missed some cool trick!

short junco
#

hah no... I had skipped ahead to day 12

hollow perch
#

Day 8 and I am already beginning to wonder if I'm near my limit now. πŸ™‚ My brain is starting to melt

short junco
#

I did crazy things for day 8 πŸ˜‰

hollow perch
#

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.||

short junco
#

oh hey, I did that for my first revisions... had a few for this particular day πŸ˜‰

hollow perch
#

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 πŸ˜„

short junco
#

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

hollow perch
#

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.

short junco
#

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 πŸ˜‰

hollow perch
#

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 😒

short junco
#

yep, which is the correct thing to do, but only for N, S, E, and W, cardinal points (if that's the right term)

hollow perch
#

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||

short junco
#

visible from NE doesn't count, so no diagonals or angles to deal with

hollow perch
#

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:

short junco
#

Would you expect the 3 to also flag up because it's higher than the highest tree you've found so far?
Yes, exactly

hollow perch
#

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.

short junco
#

if it helps at all, ||I ended up with 4 loops||

hollow perch
#

That's reassuring πŸ™‚

#

Thanks!

short junco
#

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||

hollow perch
#

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||

short junco
hollow perch
#

Oh that's interesting. I hadn't considered that!

short junco
#

doing all that meant that pt 1 ran in 128ms in the end which was about as fast as I could possibly get

hollow perch
#

||```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 πŸ™‚

short junco
#

yeah, very similar. I didn't even bother ||merging those loops into one|| despite the repetition πŸ™‚

hollow perch
#

Whaaat! Now the elves have decided they don't want their tree house hidden, they want it to overlook other trees! πŸ˜…

hollow perch
#

Second part was easier. Always seems to be easier once you've laid down the foundations

spice prism
#

|| $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

hollow perch
azure grail
#

@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

spice prism
hollow perch
spice prism
#

Haven’t been able to touch it yet. Day job and stuff

spice prism
#

@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

hollow perch
#

Ah nice one! Congrats on sorting it!

sly reef
#

@azure grail thanks, alot of these is about parsing the input.

sly reef
#

@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

short junco
#

ah yeah, that's where I stopped

sly reef
#

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? ||

short junco
#

yeah, for me I think it reduced it to a single range

umbral pond
#

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.

short junco
#

you sure this is in the right place? πŸ˜‰

umbral pond
#

NO XD I just noticed

#

Why the heck did i land here XD