#2024 AoC Day 2

99 messages ยท Page 1 of 1 (latest)

fluid olive
#

Man, they made this puzzle a real hard one today...

#

235/109 but I blame having to fight with the website refusing most of the requests I sent at it...

solemn vault
#

servers on fire

fluid olive
#

there are solutions on the leaderboard with times shorter than how long it took me to load the puzzle for the first time

solemn vault
#

yeah

old timber
#

do I want Excel or actually code...?

#

R. Huh, didn't change as much as I expected.

brittle moat
#

I got the site being down at first, too

#

I spent a hilariously long time ||excluding the wrong rows|| on part 2, classic stupid mistake

stable lichen
#

Another easy one

brittle moat
#

I didn't ||undo enough of part 1|| which is what I get for ||using it as a starting point even though that's normally a good idea||

old timber
#

easy road continues, never to get hard

brittle moat
oak wing
#

||I didn't exactly finish Part 1 with my code working properly but apparently all the passing trials were at the bottom so I just checked for the latest failure reported and subtracted the line # from 1000||

#

||fixed it properly for Part 2, where I got tripped up by not properly copying a list and accidentally just making a reference instead||

old timber
#

my first attempt said "break a rule? safe!"

inland kraken
#

Part 1 was easy enough, part 2 I feel I was very inefficient
|| I just checked every version (removing one value) for each unsafe report, until I found a safe one. If the reports had been quite long it would have taken forever. ||

oak wing
#

I dont wanna post my code it's literally my first time and it'll be some matter of messy and silly

oak wing
inland kraken
#

The "smart" way to do it would be || to look at only the increaase/decrease that caused a failure, and try removing the numbers before and after ||
But I couldn't be bothered

oak wing
#

that seems like it would take way longer to do anyways

#

for anyone who cares about speed points

old timber
inland kraken
#

Yeah, but if it's anything like last year, later problems you can't really get away with brute force, so I'm trying to not get in the habit

oak wing
old timber
#

generally "is there a trick? if so, the puzzle will be such that brute forcing will make the runtime impractical". Fortunately, we will have only easy puzzles this year in which brute force is linear time!

oak wing
#

mhm sure

inland kraken
#

You know, I'm happy to be learning how to use map and filter, but wow does it make things less readable (imo)

#

Also debugging using print is harder cause printing them out just give <map object> or whatever, instead of the contents

stable lichen
#

I was VERY inefficient with my solve. Might as well have done it manually.

#

But hey, a star's a star.

solemn vault
#

that's the way it is

#

here's my mess for today:

||```py
from aocd import data
lines = data.split('\n')

o = 0

for l in lines:
r = list(map(int, l.split()))
for j in range(len(r)+1):
if j == 0:
u = r
else:
u = r[:j-1]+r[j:]
if u != sorted(u) and u != sorted(u)[::-1]:
continue
b = 0
for i in range(len(u)-1):
k = abs(u[i]-u[i+1])
if k == 0 or k > 3:
b = 1
break
if not b:
o += 1
break

print(o)

fluid olive
#

||Me, trying to remember how you efficiently check if a list is monotonic: so, you can zip it with itself, and check the ordering, and... then check all those orderings are the same? like, collect the orders, and check for distinct values? hmm, how to do this cleanly... wait, how long are these input lists again? very short, you say? eff it, s == sorted(s)||

#

||This also makes me two-for-two on puzzles where there's some aspect of the Python language/library that I didn't remember off the top of my head, and checking would have taken more time than just writing the code to cover for all possibilities. In this case, I couldn't remember whether sorted returned a list or an iterator, so my code has list(sorted(s)) which, it turns out, does an unnecessary copy. Yesterday, I couldn't remember if collections.Counter has a default value or throws a KeyError, so I wrote b.get(i, 0) instead, which was also unnecessary. But in either case, actually checking if it was necessary would have taken more time than I saved.||

solemn vault
#

I did have an issue in the first version of my code of ||comparing a map object to a list for equality||

#

what the hell is a collections.Counter?

fluid olive
#

oh, I did a simliar thing ||I did s == list(sorted(s)) but my s was actually a tuple||

fluid olive
solemn vault
#

ah, neat

#

more efficient than myList.count(2), I guess

#

if you need repeated access

fluid olive
#

yeah, 'cause it only has to scan the input sequence once, and uses hashmap magic to collect duplicates

solemn vault
#

when I have to do that sort of thing efficiently I usually just use a Defaultdict

fluid olive
native seal
#

I feel like it turned out clean enough for this early in the event

inland kraken
#

Oh, I didn't think of ||sorting to check for if it was increasing/decreasing||, that's smart

vivid mason
#

Im struggling to work out why my solution for part 1 is failing,|| i've got to the point where im printing all the lines where it is deeming the line to be "safe", and going through each one by one
but all seem to match the criteria, they all have the same sign, and the largest difference is 3||

indigo tide
vivid mason
#

the annoying thing is, the test data works perfectly, so there must be another hidden edge case

fair cave
vivid mason
fair cave
#

wait, are those hard-coded numbers of levels?

vivid mason
#

I'll just share the whole code

fair cave
#

yeah, you've hardcoded the number of levels

vivid mason
#

ah, i see

#

i need to change some stuff ||to be based on length(work)||

#

thats what i get for not fully checking what the real data looked like

vivid mason
#

Had to go do my job for a bit, but part two wasnt too bad, ||figured i'd move my check into a function, and just run a temporary report through it for part 2||

wide snow
#

The switch to Python from Excel this year was early. I just didn't want to deal with today's problem in Excel, specifically the ||variable length of inputs|| would just be annoying to deal with. I'm sure Excel has a nice way of doing that but I don't really want to try it.

#

I did learn the syntax for filtering inside of a Python list comprehension today, though.

next crow
#

switched to python from c++ this year and idk if maybe I'm just bad at c++ (or probably both) but python seems to require less writing to do the same thing so that's nice

next crow
fair cave
#

That's correct. It's a lot faster in the cases where the input scales in that direction. But today wasn't about stressing your scaling in that direction.

next crow
#

yeah, totally agree it's not necessary! ๐Ÿ˜„

inland kraken
fair cave
#

That analysis was for a single report.

#

Multiply each by the number of reports for a description of the scaling of the whole solution

inland kraken
#

Big O notation is about the general case of the algorithm, though

fair cave
#

Sure, but define "the algorithm" for a single report.

#

There's no way to do anything more interesting than process each report independently anyway.

mellow verge
#

alright, well that's a very dumb spreadsheet

#

there are maybe cleverer ways but whatever

#

definitely spent too long trying to find the cleverer ways

#

very very dumb

oak wing
#

feeling smug watching my sister and her boyfriend try to do things the clever way and take way longer than i did

mellow verge
#

and not sure if there's a better construction that does similar

wide snow
brisk hornet
#

Part 1 tripped me a couple of times and then refactoring for 2 I managed to flip my logic without noticing and was counting the bad reports

#

and p2 continues to trip me up, I'm low but I don't know why
||I'm kept my logic but now I output all the bad indexes. If the list has bad levels I copy it, remove one and check again for bad indexes then repeat for the other bad levels. My totally safe reports is still good but my reports with dampener is too low||

old timber
#

do you want to post your code for suggestions?

brisk hornet
#

<placeholder for removed code>

old timber
#

a question ||is it reporting the right bad indexes? for safe reports, there are no bad indexes, but where there are problems, if it isn't returning the right list, then the dampening might not remove it||

brisk hornet
#

||oh yeah... it could be that by removing the previous value it resolves it... thanks||
||didn't help... brute forcing it is... realised that whether its asc or desc could be wrong and and that wouldn't trigger with my logic||

mellow verge
#

yeah the difficulty ||locating "which" one is the error or which one to remove is why i ended up just trying to remove all of them||

inland kraken
#

||Remove all reports. No bad reports. Problem solved.||

brisk hornet
#

||ah what fun... my bruteforcer isn't brute forcing. Its missing the last index for some reason?||
||Dammit, range isn't inclusive||

#

Got it in the end with brute force... now to see if I could have done it better from these comments ๐Ÿ˜„

old timber
#

Brute force! Brute Force!! BRUTE FORCE!!!

brisk hornet
#

that's enough for tonight I think... its 11pm. I'll take on the other tomorrow ๐Ÿ˜ฆ

brisk hornet