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

feat: Introduce hamming code generator #11827

Open
wants to merge 34 commits into
base: master
Choose a base branch
from

Conversation

AyushChakraborty
Copy link

Introduced a new .py file which generates 16 bit
hamming codes from the given 11 bit input.
Additional 5 bits are redundant, used to correct
single bit errors within the data bits

Describe your change:

Introduced a new .py file called hamming_code_generator.py which generates 16 bit hamming codes. 5 bits introduced are for redundancy and used to check and correct for a single bit change anywhere in the final 16 bit binary number. Doctests are written and all other rules mentioned in the checklist and README.md file are followed by me.

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

Introduced a new .py file which generates 16 bit
hamming codes from the given 11 bit input.
Additional 5 bits are redundant, used to correct
single bit errors within the data bits
@algorithms-keeper algorithms-keeper bot added the require descriptive names This PR needs descriptive function and/or variable names label Oct 6, 2024
Copy link

@algorithms-keeper algorithms-keeper bot left a comment

Choose a reason for hiding this comment

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

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

bit_manipulation/hamming_code_generator.py Outdated Show resolved Hide resolved
bit_manipulation/hamming_code_generator.py Outdated Show resolved Hide resolved
bit_manipulation/hamming_code_generator.py Outdated Show resolved Hide resolved
bit_manipulation/hamming_code_generator.py Outdated Show resolved Hide resolved
@algorithms-keeper algorithms-keeper bot added the awaiting reviews This PR is ready to be reviewed label Oct 6, 2024
@algorithms-keeper algorithms-keeper bot added the tests are failing Do not merge until tests pass label Oct 6, 2024
changed name of x, y to temp_bit1, temp_bit2
respectively
github.com:AyushChakraborty/TheAlgorithms into
branch1
@algorithms-keeper algorithms-keeper bot removed the require descriptive names This PR needs descriptive function and/or variable names label Oct 6, 2024
@AyushChakraborty
Copy link
Author

will change the names of x, y to temp_bit1, temp_bit2

AyushChakraborty and others added 2 commits October 6, 2024 18:43
Changed the code according the feedback given
by failed PR

(TheAlgorithms#11827)
@algorithms-keeper algorithms-keeper bot removed the tests are failing Do not merge until tests pass label Oct 6, 2024
@AyushChakraborty
Copy link
Author

made the lines in the docstring shorter, imported modules according to the specified norm and added k values to a list and used membership operation instead of checking the values of k individually in one of the if statements

bit_manipulation/hamming_code_generator.py Outdated Show resolved Hide resolved
bit_manipulation/hamming_code_generator.py Show resolved Hide resolved
bit_manipulation/hamming_code_generator.py Outdated Show resolved Hide resolved
bit_manipulation/hamming_code_generator.py Outdated Show resolved Hide resolved
bit_manipulation/hamming_code_generator.py Outdated Show resolved Hide resolved
AyushChakraborty and others added 3 commits October 8, 2024 09:11
changed code based on suggestion by
@jeffreyyancey, fixed up some docstring, links
and wrote code for finding redundant bits using
for loops instead of reduce and lambda, for
readability
@algorithms-keeper algorithms-keeper bot added tests are failing Do not merge until tests pass and removed tests are failing Do not merge until tests pass labels Oct 8, 2024
@AyushChakraborty
Copy link
Author

@jeffreyyancey added the appropriate changes

@jeffreyyancey
Copy link
Contributor

The only concern I have left is that it doesn't appear your are enforcing that the number that comes in contains only "0" or "1" characters. It appears to just be converting any character that isn't a "0" to 1. So a string like "#&! & ((30qhjj1+" would be accepted and become 1111111110111111.

@AyushChakraborty
Copy link
Author

The only concern I have left is that it doesn't appear your are enforcing that the number that comes in contains only "0" or "1" characters. It appears to just be converting any character that isn't a "0" to 1. So a string like "#&! & ((30qhjj1+" would be accepted and become 1111111110111111.

Oh yes, I completely overlooked this, thanks I'll make the changes.

@algorithms-keeper algorithms-keeper bot added the tests are failing Do not merge until tests pass label Oct 8, 2024
@algorithms-keeper algorithms-keeper bot removed the tests are failing Do not merge until tests pass label Oct 8, 2024
@AyushChakraborty
Copy link
Author

Updated the code, can you, if possible merge the PR now?

Copy link
Contributor

@jeffreyyancey jeffreyyancey left a comment

Choose a reason for hiding this comment

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

Everything looks like it is working well, just a couple minor things and I'd be happy to approve.

Primarily, can you remove r since it is no longer used in this implementation, and can you update the couple variable that need more descriptive names.

bit_manipulation/hamming_code_generator.py Show resolved Hide resolved
bit_manipulation/hamming_code_generator.py Outdated Show resolved Hide resolved
bit_manipulation/hamming_code_generator.py Outdated Show resolved Hide resolved
bit_manipulation/hamming_code_generator.py Outdated Show resolved Hide resolved
@algorithms-keeper algorithms-keeper bot added tests are failing Do not merge until tests pass and removed tests are failing Do not merge until tests pass labels Oct 8, 2024
@algorithms-keeper algorithms-keeper bot added the tests are failing Do not merge until tests pass label Oct 8, 2024
github.com:AyushChakraborty/TheAlgorithms into branch1
@algorithms-keeper algorithms-keeper bot removed the tests are failing Do not merge until tests pass label Oct 8, 2024
@algorithms-keeper algorithms-keeper bot added the tests are failing Do not merge until tests pass label Oct 8, 2024
@algorithms-keeper algorithms-keeper bot removed the tests are failing Do not merge until tests pass label Oct 9, 2024
@AyushChakraborty
Copy link
Author

@jeffreyyancey implemented the pop method

Copy link
Contributor

@jeffreyyancey jeffreyyancey left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@AyushChakraborty
Copy link
Author

@jeffreyyancey this is actually my first open source contribution, so do you have any idea how the PR can be accepeted into the main repo?

@jeffreyyancey
Copy link
Contributor

I believe that one of the admins needs to give their approval. Approvals from other users will not allow merging. Instead, it helps find any issues prior to one of the individuals with the rights to approve for merging to view.

@AyushChakraborty
Copy link
Author

Ok got it, thanks for the help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reviews This PR is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants