Skip to content

feat: added Project Euler Problem 13#1150

Merged
raklaptudirm merged 11 commits into
TheAlgorithms:masterfrom
byt3h3ad:master
Oct 12, 2022
Merged

feat: added Project Euler Problem 13#1150
raklaptudirm merged 11 commits into
TheAlgorithms:masterfrom
byt3h3ad:master

Conversation

@byt3h3ad

@byt3h3ad byt3h3ad commented Oct 8, 2022

Copy link
Copy Markdown
Contributor

Open in Gitpod know more

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • 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 JavaScript files are placed inside an existing directory.
  • All filenames should use the UpperCamelCase (PascalCase) style. There should be no spaces in filenames.
    Example:UserProfile.js is allowed but userprofile.js,Userprofile.js,user-Profile.js,userProfile.js are not
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

@appgurueu

Copy link
Copy Markdown
Collaborator

Your checks are failing.

@byt3h3ad

byt3h3ad commented Oct 8, 2022

Copy link
Copy Markdown
Contributor Author

all errors have been fixed @appgurueu

@byt3h3ad

Copy link
Copy Markdown
Contributor Author

@appgurueu @raklaptudirm any changes needed?

@appgurueu

Copy link
Copy Markdown
Collaborator

I don't think this algorithm is correct in the general case. The numbers given are well below what JavaScript numbers (64-bit floats) can safely represent; that is, they exceed MAX_SAFE_INTEGER by a lot and get truncated to the first n of their most significant digits. When you now add all these numbers, you have some error. Can you rule out the possibility that this error might cause the results to be wrong? For the given test case it might work, but does it work in general? Even if it did, it wouldn't be apparent why (and would be deeply reliant on floating-point intricacies).

The proper solution is to use big integers to exactly represent the given numbers.

turns out there was indeed an error because of not using BigInt
@byt3h3ad

Copy link
Copy Markdown
Contributor Author

@appgurueu thanks for the feedback! I have now used BigInt, and turns out there was indeed an error xD.

Comment thread Project-Euler/Problem013.js Outdated
@raklaptudirm raklaptudirm merged commit 514c7c4 into TheAlgorithms:master Oct 12, 2022
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.

3 participants