#2024 AoC Day 4

84 messages · Page 1 of 1 (latest)

humble basin
#

This one's TOO easy

chilly sky
#

It's day 4

humble basin
#

Good ol' Excel, nothing beats that!

wicked wasp
#

Nope, just making a mess of this

valid fulcrum
#

For part 1 ||I already had a solution for, in another project... but I had to find that past project, dig out the right function, generalise it a bit... ended up pretty low on the leaderboard. Meanwhile, part 2, I built anew from scratch here, and it ended up doing much better. Lesson learned: never reuse anything.||

wicked wasp
#

WOW Part 2 was SO MUCH SIMPLIER than Part 1 !!

humble basin
#

"or even overlapping other words" is what scared me.
I thought it'd be impossible for me to solve if "XMsomethingAS" was valid.

wicked wasp
#

I basically ||hardcoded searching all ways for XMAS and SAMX||

humble basin
#

It's just 8 ways

wicked wasp
#

it'd be quicker if I could suppress "Out of Bounds" errors...

chilly sky
#

I worked around that just fine 😛

#

I like my part 2 solution notably more than I like my part 1 solution, for what that's worth

maiden oasis
#

A bunch of off-by-one error and incorrect signs for checking in different directions, but generally no actual trouble

#

Basically just ||checked in each direction at each point||

#

had a funny problem in part one where it found an extra one, cause it ||was looping at the edge thanks to python letting you index negative numbers (and me screwing up the check to stop that)||

modern hatch
limpid patio
#

“Ceres Search”… how did the AoC people get hold of my notes??
(Spent most of the last quarter upgrading and retooling a lot storage system called Ceres

modern hatch
#

it was also unsurprisingly jank

limpid patio
modern hatch
#

this is what i get for coding at 11pm

#

||i didnt even bother simplifying the last array indices...||

modern hatch
#

that was not a problem in part2

maiden oasis
#

This was the main logic of mine

#

I started out ||just doing the big list of directions, and then later decided to use a direction variable to make parts easier, and I think I could make all this logic much simpler if I used to there as well|||

modern hatch
#

imagine defining things

#

i have yet to bother with that. i really should do that eventually

#

i just. havent bothered to

#

im sure ill start doing things more properly when i have to

maiden oasis
#

I also ||optimistically allowed it to work for any word, thinking that might change in part 2
Of course once I got to part 2, and could just hard code it in, it got a lot smaller||

#

ok, yeah, that's way more compact, and honestly, easier to read

quaint saddle
#

I got the brilliant idea to solve part 1 using a technique I saw once for the 8 queens problem, where diagonals are stored in a separate data structure.

#

It worked!

#

It was utterly useless for part 2

#

Then again, what I did for part 2 is utterly useless for part 1, so... eh.

wicked wasp
frozen violet
#

I didn't see any in my example, so decided to not bother with the possibility

#

Also, it turns out things run a lot better if you don't accidentally put the y and x output of one method as the x and y input of another...

crisp cedar
#

and I was once again annoyed by dir being a builtin in python

valid fulcrum
limpid patio
#

Oh wait are you the one who posted the full stats for that?

rancid eagle
#

Im not proud of how i solved this, but it works

#

my first attempt failed ||when I couldnt do basic maths properly, and so all the "4"s in the checks for boundaries were set to "3"||

stray plover
#

Should've gone to work already but I have no idea why my quick code is apparently getting the wrong answer. Will look when I get home I guess:
||```
with open("D4.input", 'r') as f:
lines = f.readlines()

#xmas +1, +n-1, +n, +n+1
#samx +1, +n-1, +n, +n+1

lines = [line.strip() for line in lines]
n = len(lines[0])
bstr = ''.join(lines)
N = len(bstr)
total = 0
exs = []
for i, c in enumerate(bstr):
if c in 'XS':
sign = 1 - 2*(c == 'S')
for gap in [1, n-1, n, n+1]:
if i + 3gap < N:
if ''.join([bstr[i + j
gap] for j in range(4)]) == 'XMAS'[::sign]:
total += 1
exs += [[i, gap, sign]]

#

Oh duh, realized in the shower ||I didn't include a line boundary check.|| I'll fix it tonight I guess

lethal drift
#

I ask a question so similar to this one when I interview people that I could do today's in my sleep.

#

I've seen hundreds of attempts at this problem.

pearl storm
#

one dumb thing you can do in a spreadsheet is put your grid down a few rows and columns and then just let your offset go "out of bounds" 😛

humble basin
#

That's how I solved it.

lethal drift
#

I love avoiding bounds checking with a more permissive data structure, yeah.

untold merlin
#

last year I wrote a whole reusable "character matrix" class that was super useful. and then today I forgot I had it and wasted like 15 minutes doing it again from scratch. that's what I get for rushing

limpid patio
#

Finally got around to solving this and being the kind of person I am, I realised that || XMAS and SMAX both fit in an int32... so my algorithm was to read the file a byte at a time, shift that byte into the appropriate row/column/diag1/diag2 integer, and see if it is equal to the two known constants. It technically makes it O(side_length) in memory usage! ||

limpid patio
#

My brain is only expanding that as the job title (which I’m guessing is not what you mean?)

green parcel
#

SIMD cpu instructions

#

(to save you a click if you just want the number: 12 GB/s)

loud skiff
#

my brain is dying trying to figure out how to do the diagonals...

loud skiff
#

I cannot work out how to get what I want for the diagonals at all...
Trying to build all the possible diagonal strings by traversing a 2d character array but failing absolutely miserably to get my brain to find a way to do it

limpid patio
#

It took me a while to work it out. My brain started craking it by || starting with the longest diagonal as the "middle" diagonal -- it has the same length as the sides. each side of it, there's a diagonal one shorter, down to one of length one. Once I realised that, the relation between the (x,y) on the grid and which diagonal got easier || but that may just be how my brain works

loud skiff
#

still not really getting it 😐

pearl storm
#

i just didn't do anything like that at all in the first place

loud skiff
#

I've been staring at this for over an hour now, Day 3 was easy and Day 4 is when I go "how have i been paid for programming for 10 year" and get depressed

wicked wasp
#

is this too simple an explanation, as in "yeah, that's obvious, I got that"? ||if you start with point p,q, you check (p,q), (p+1,q+1), (p+2,q+2), (p+3,q+3), for one direction, and (p,q), (p+1,q-1), (p+2,q-2), (p+3,q-3) for the other? (I checked for XMAS and SAMX). [Boundary checking as you need to]||

loud skiff
#

still not getting this one 😐
||Bad Code here: https://github.com/jamstruth/advent-of-code-2024/blob/main/day4.py||
||Trying to go through from top-left to bottom-right checking for XMAS or SAMX. Only Checking Right, Down, Down-Right and down-left to avoid any double-counting (a SAMX Down-Right is the same as an XMAS up-left) Not telling me if I'm low or high||

wicked wasp
#

I can suggest running this on the example, and outputting your tests. I can see already that you will be missing things in the bottom row/right hand column. Consider a bottom row "XMAS", you don't get there because you stop at len-step_value

#

(and there is no down-left test in that code)

loud skiff
#

Could have sworn I'd committed it

#

down to missing 1 in the test data now

wicked wasp
#

down-left was my downfall.

loud skiff
#

got it, ||bad col offset check. failed if it was exactly 0||

wicked wasp
#

boundary conditions are fun!! (no, no they aren't)

loud skiff
#

got part 2 fairly quick after that struggle with part 1... Just banging my head on my first idea and then being angry