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

Fixed Problem 1 example for 1-based indexing #175

Closed
wants to merge 1 commit into from

Conversation

svilupp
Copy link

@svilupp svilupp commented Aug 26, 2024

Fixing the provided example for Julia's 1-based indexing

Fixing the provided example for Julia's 1-based indexing
@RexWzh
Copy link
Collaborator

RexWzh commented Aug 26, 2024

Thanks, @svilupp, for your contribution.
The problem text aligns with the one on leetcode.com; specifically, for this instance, Two Sum Problem Description.

Moreover, I believe that managing indices is more a concern of algorithm design and should not be a fixed requirement within the problem statement.

@svilupp
Copy link
Author

svilupp commented Aug 26, 2024

I'm not sure I follow your explanation.

Are you saying that it's okay that the examples provided do not execute correctly?
Eg, Because nums[0] + nums[1] == 9, we return [0, 1] will throw an out of bounds error.

Or maybe you're saying that it should be exactly the same as Python (0-based indexing), in which case the solution is wrong because it's using 1-based enumerate for indexing: for (i, n) in enumerate(nums).

Or maybe you meant something else? I merely pointing out that the solution doesn't align with the examples.

@RexWzh
Copy link
Collaborator

RexWzh commented Aug 26, 2024

I mean, you can treat it more like pseudocode rather than real code.
For instance, the syntax nums = [3,2,4] is not valid in C, but it is acceptable for illustrating examples.

image


Moreover, there have been discussions about adding Julia to LeetCode (hopefully, it will happen one day). It might be convenient to keep the text consistent with leetcode.com.

@RexWzh
Copy link
Collaborator

RexWzh commented Aug 26, 2024

Contributions are warmly welcomed, and here's how to get started:

  1. First, create a new file for an unsolved problem:
cd LeetCode.jl
# Generate a new solution file for unsolved problem 38
julia scripts/newsolution.jl 38
  1. Next, write the solution and tests in scripts/presolution/38.xxx.jl.

  2. Then, convert the draft solution and tests into their final form using the following command:

julia scripts/submit.jl 38

After thoroughly testing the solution, commit the changes and push them to the repository using git.


Other types of contributions are also appreciated. For instance, one can add more problem templates from leetcode.com (most of them are generated through scraping) or improve the existing scripts in the scripts directory.

Thank you for the support and collaboration!

@svilupp
Copy link
Author

svilupp commented Aug 26, 2024

Thank you for the explanation! I misunderstood the purpose / conditions — I assumed it’s meant to be valid Julia code for newcomers, but I understand now that you prioritize the consistency with LC descriptions.

I noticed it because I was building a synthetic data set of code optimization feedback (for finetuning an LLM) and I had to add a 3-round self-reflection to fix a lot of these examples to be runnable. Good to know for the future!

@svilupp svilupp closed this Aug 26, 2024
@svilupp svilupp deleted the patch-1 branch August 26, 2024 10:37
@RexWzh
Copy link
Collaborator

RexWzh commented Aug 26, 2024

Oh, I see. You're building a synthetic dataset of code for fine-tuning an LLM.

The texts in src/problems are simply duplicates from leetcode.com without any adaptation to Julia. It requires the same effort to convert the text from leetcode.com to Julia style. However, the codes and tests in this repository could still be quite helpful.

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