Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

day 23 py #75

Merged
merged 3 commits into from
Dec 23, 2023
Merged

day 23 py #75

merged 3 commits into from
Dec 23, 2023

Conversation

RongkunWang
Copy link
Collaborator

@RongkunWang RongkunWang commented Dec 23, 2023

First need to build up the proper graph.

Then solve the problem of "longest path between two nodes in a graph". Unfortunately, Eric put plenty of cycles inside, and in part 2 it's guaranteed to be undirected, therefore there's no tricks. Although it seems Eric make the part 1 a directed graph, using the brute force approach is still very fast.

It took 30 second on my computer..

I plan to make a figure out of it(idea from Marco)

@RongkunWang RongkunWang marked this pull request as draft December 23, 2023 17:02
@RongkunWang
Copy link
Collaborator Author

RongkunWang commented Dec 23, 2023

all junction and their path.
23_full_trace

@RongkunWang

This comment was marked as outdated.

@Moelf
Copy link
Owner

Moelf commented Dec 23, 2023

beautiful

@RongkunWang
Copy link
Collaborator Author

I'm happy he didn't just allow greedy algorithm find the solution :D

Part 1

23_graph_part1

Part 2

23_graph_part2

However python is still very slow!

@RongkunWang RongkunWang marked this pull request as ready for review December 23, 2023 21:26
@Moelf
Copy link
Owner

Moelf commented Dec 23, 2023

However python is still very slow!

Use pypy?

@RongkunWang
Copy link
Collaborator Author

Baseline: 30-40 second

  1. recursion to avoid copying of list. about 10 s improvement but subject to fluctuation
  2. do not return the solution, to avoid copying. no significant changes
  3. use set for visited(not able to track the path anymore). 7 second 😈 . Wow so the the time really is spent at "did I visit this before?
  4. map out nodes to indices for the grpah. avoid any unoptimal time complexity for add/find/remove for set. 4 second 😆

btw, when you merge from your branch to main, does github ask you to merge main to my branch? Becuase I usually don't do the merge, I rebase, so that I can keep the history better sorted.

@RongkunWang RongkunWang marked this pull request as ready for review December 23, 2023 22:42
@RongkunWang RongkunWang merged commit 74ee87f into main Dec 23, 2023
1 check passed
@RongkunWang RongkunWang deleted the rk/py branch December 23, 2023 22:43
@Moelf
Copy link
Owner

Moelf commented Dec 24, 2023

Oh, I clicked update for this PR when I merged my so we can run on real inputs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants