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

Add rust code for backtracking problems #79

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

nikhilmitrax
Copy link

Mainly porting the python algorithms, and trying to follow similar paradigm as the python code.

Mostly written by hand, albeit with AI autocomplete on.

Copy link
Collaborator

@Destiny-02 Destiny-02 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @nikhilmitrax, thank you for writing the Rust solutions for the Backtracking chapter! Looks good overall, just a few comments for you to check.

@@ -0,0 +1,41 @@
pub fn combinations_of_sum_k(nums: Vec<i32>, target: i32) -> Vec<Vec<i32>> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing rust solutions in the Sliding Windows chapter don't use pub fn. If there is a reason to use pub fn instead of fn, please update the solutions in Sliding Windows. Otherwise, we can stick to fn.

Copy link
Author

@nikhilmitrax nikhilmitrax Mar 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe pub fn makes more sense since the functions aren't really useful without having public visibility and being isolated in a file.

As is, the rust functions aren't particularly usable without a module setup and at least a project definition (Cargo.toml)

I see 3 potential paths moving forward, and I'm perfectly fine with all 3 options, do you have a preference?

Options:

  1. Remove pub everywhere
  2. Add pub to all functions that should be usable outside a file.
  3. Add pub to all functions that should be usable outside a file, and add a Cargo.toml (possibly along with lib.rs and some tests, so that cargo test runs through the examples)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Option 1 please!
Here is some background if you're interested: #54 (comment)

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