#Day 10 Solutions
74 messages · Page 1 of 1 (latest)
Can make it prettier and more efficient on part 1
Woah
thats a lot of code pepe_hmm
Contribute to milindmadhukar/Advent-Of-Code development by creating an account on GitHub.
Mines a lot simpler
Yeah, have a lot of dupe
Is it just me or has AOC been easier this year? I would have been struggling by now, yet till now seems a breeze
It is still early
Weird math shall arrive soon
You might just be a better programmer than you were a year ago
got part1 done, in color
and lol, same, my first version was part2 too
with sleep so it's visible
free with recursion
am I the only one who accidentally solved part 2 before part 1

we all did I think
Android is so awesome
def get_trails(x, y, num):
if not (0 <= x < x_len and 0 <= y < y_len): return set()
if data[x][y] != num: return set()
if num == 9:
return {(x, y)}
return reduce(or_, starmap(get_trails,[(x+1, y, num+1), (x-1, y, num+1), (x, y+1, num+1), (x, y-1, num+1)]), set())
# %%
trails = 0
for i in range(x_len):
for j in range(y_len):
trails += len(get_trails(i, j, 0))
print(trails)```
one last video
wow your python-fu is strong
Mine is not nearly as good
its interesting you also pass the num you're looking for, wouldnt have thought of that
fairly proud of my
set().union(*[descend_set((pos[0] + dx, pos[1] + dy), g) for dx, dy in directions if 0 <= pos[0] + dx < len(g) and 0 <= pos[1] + dy < len(g[0]) g[pos[0] + dx][pos[1] + dy] == g[pos[0]][pos[1]] + 1])
its a tad long to fit in a line
Not me
For part one I used a bit set
And I'm seeing part 2 and "oke, hashmap it is"
Part 2 was so free today
I partially did 2021 and 2022
And iirc second weeks were slightly easier before slingshotting to difficult stuff

I too did part2 first by accident
I did as well
python has reduce???
Of course
functools
although yeah set.union would've been cleaner
Guido also wanted to remove map and filter but they cancelled him for it or somehing
idk the lore
yeah python's map/filter/reduce isn't the bes
I do wish we had first class support for them a la haskell but
asking for anything a la haskell is wishing upon the monkeys paw
Dude wtf did anyone else just have to comment out an assignment to the visitedNodes map to get part 2 from part 1 ? Literally all I had to do was comment out a single line
Ur just getting better
many such cases
I first misunderstood the part one assignment and got 81 on the example input
then I fixed it
then I saw part two wanted 81 on the example input and was kinda vibing
tbh more like part1 = len(visitedNotes) vs part2 = sum visitedNodes values
I did same thing
For something like part 2 where you just want to find all the unique paths, does BFS vs. DFS matter still? I would think for part 1 DFS would be the way to go but I also don't rly know what I'm yapping about
dfs has lesser memory requirement
well it depends upon the scenario but
shouldnt really make a difference no
Ok that's what I thought
DFS is natural with recursion... BFS is if you do your work queue yourself no?
Yeah but if u do it iteratively they r basically the same except dfs uses stack and bfs uses queue.... Which I think is what you're saying. So yes
append at the end or insert in front if doing it yourself yes
i accidentally did part 2 first
is this a memory crime
||
to_be_checked = to_be_checked[1:]
||
This is fine. The slice header is on the stack