Skip to content

feat: python impl for 0-1 BFS #1336

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

Closed
wants to merge 5 commits into from
Closed

Conversation

clumsy
Copy link
Contributor

@clumsy clumsy commented Sep 23, 2024

Adding python implementation, fixing a minor grammatical error.

@adamant-pwn
Copy link
Member

adamant-pwn commented Oct 11, 2024

Thanks for the pull request! Could you please rebase it on the current master branch, so that workflows run correctly? Also I noticed that you have provided an implementation of Dijkstra algorithm using set, which unfortunately wouldn't work because Python's sets are based on hash-tables, and as such don't produce the smallest element.

What you actually want here is probably heapq, could you please update the pull request using it? Also, did you check your code on any specific problems?

@clumsy
Copy link
Contributor Author

clumsy commented Oct 13, 2024

Thanks for the pull request! Could you please rebase it on the current master branch, so that workflows run correctly? Also I noticed that you have provided an implementation of Dijkstra algorithm using set, which unfortunately wouldn't work because Python's sets are based on hash-tables, and as such don't product the smallest element.

What you actually want here is probably heapq, could you please update the pull request using it? Also, did you check your code on any specific problems?

Sure, tried to follow the C++ original as much as possible. It worked for several test cases, but I'll switch to heapq and rebase.

@wqweto
Copy link

wqweto commented Oct 13, 2024

@clumsy Please don't indent codeblock's backticks in markdown i.e. make sure ```cpp stays at the beginning on the line.

@adamant-pwn
Copy link
Member

adamant-pwn commented Oct 13, 2024

Indenting here is okay, because it uses Material's content tabs feature.

@clumsy
Copy link
Contributor Author

clumsy commented Oct 13, 2024

Indenting here is okay, because it uses Material's content tabs feature.

Exactly, without this change there are no C++/Python tabs to switch from. This follows the same format as other pages with examples in two languages.

@jxu
Copy link
Contributor

jxu commented Oct 14, 2024

Personally I think there should only be one implementation, and a good reason to have multiple. If we have python as pseudocode, then it shouldn't be hidden in a content tab. My 2c

@adamant-pwn
Copy link
Member

I'm generally fine with having both C++ and Python. The latter is more beginner-friendly, mostly simple to review and can also be used in problems where performance doesn't matter as much, e.g. for Project Euler problems, which is also the reason I've included both in continued fractions article (well, and also because with continued fractions, you are much more likely to require big integers). I think it's fine to use it as a second default, when available. It doesn't really take anything from article's quality, and can be useful for some people.

Hiding it in content tabs is, IMO, fine because the majority of CPers still use C++, and using tabs allows to preserve article space, so that only people for whom Python code would actually be useful will actually open it.

@clumsy
Copy link
Contributor Author

clumsy commented Oct 14, 2024

+1 to what @adamant-pwn said.
Also, I've addressed your comment, please let me know if there's more to edit.

@adamant-pwn adamant-pwn deleted the branch cp-algorithms:main October 14, 2024 18:52
@adamant-pwn adamant-pwn reopened this Oct 14, 2024
@adamant-pwn adamant-pwn changed the base branch from master to main October 14, 2024 19:18
Copy link
Contributor

Preview the changes for PR #1336 at https://gh.cp-algorithms.com/1336/ (current version: 9260362).

@clumsy
Copy link
Contributor Author

clumsy commented Oct 24, 2024

The base branch changed, will cut another PR.

@clumsy clumsy closed this Oct 24, 2024
github-actions bot added a commit that referenced this pull request Oct 24, 2024
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.

4 participants