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 17 py; Dijkstra's algorithm #64

Merged
merged 3 commits into from
Dec 17, 2023
Merged

day 17 py; Dijkstra's algorithm #64

merged 3 commits into from
Dec 17, 2023

Conversation

RongkunWang
Copy link
Collaborator

Fun problem.

I basically used a FIFO to record the optimal scenario for each tile, considering the history(direction that that went into this tile and that's the nth step(1..3..10) of a straight line.

It took 60 second for solution 1 and 80 seconds for solution 2.

@RongkunWang
Copy link
Collaborator Author

I suspect if I record the starting point and stop considering and just update all existing start/stop map, it'll save even more time.

@RongkunWang
Copy link
Collaborator Author

It looks like I might be stumbling on a Dijkstra's algorithm solution except I didn't think of a weighted graph case and simply used deque for a WFS.

Trying priority queue and it reduced the total time to 2second.

It makes sense to put the loss as a score in priorty queue and consider first in its pop out.

@RongkunWang RongkunWang changed the title day 17 py. Slow day 17 py Dec 17, 2023
@RongkunWang RongkunWang changed the title day 17 py day 17 py; Dijkstra's algorithm Dec 17, 2023
@RongkunWang RongkunWang merged commit 9fbad30 into main Dec 17, 2023
1 check passed
@RongkunWang RongkunWang deleted the rk/py branch December 17, 2023 18:30
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.

1 participant