#Day 10 Solutions

74 messages · Page 1 of 1 (latest)

wispy lynx
#

digits

warped compass
#

Can make it prettier and more efficient on part 1

pliant wren
#

Mines a lot simpler

warped compass
#

Yeah, have a lot of dupe

hasty plume
pliant wren
#

Is it just me or has AOC been easier this year? I would have been struggling by now, yet till now seems a breeze

wispy lynx
#

It is still early

#

Weird math shall arrive soon

#

You might just be a better programmer than you were a year ago

formal copper
#

got part1 done, in color

#

and lol, same, my first version was part2 too

gleaming peak
#

free with recursion

#

am I the only one who accidentally solved part 2 before part 1

formal copper
#

we all did I think

gleaming peak
gleaming peak
# gleaming peak 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)```
formal copper
paper schooner
#

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

spark rose
#

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

spark rose
#

And iirc second weeks were slightly easier before slingshotting to difficult stuff

gleaming peak
wispy lynx
#

I too did part2 first by accident

paper schooner
wispy lynx
#

Of course

spark rose
gleaming peak
#

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

paper schooner
#

the UX sucks for those

#

give me pipes

gleaming peak
#

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

primal bear
#

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

gleaming peak
#

many such cases

paper schooner
#

then I fixed it

#

then I saw part two wanted 81 on the example input and was kinda vibing

spark rose
primal bear
#

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

gleaming peak
#

dfs has lesser memory requirement

#

well it depends upon the scenario but

#

shouldnt really make a difference no

primal bear
#

Ok that's what I thought

formal copper
#

DFS is natural with recursion... BFS is if you do your work queue yourself no?

primal bear
formal copper
#

append at the end or insert in front if doing it yourself yes

fickle lake
#

i accidentally did part 2 first

fickle lake
#

is this a memory crime
||

to_be_checked = to_be_checked[1:]

||

paper schooner