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

Fix undefined_operator in fermats_little_theorem.dart #141

Closed
wants to merge 3 commits into from

Conversation

akashgkrishnan
Copy link
Contributor

@akashgkrishnan akashgkrishnan commented Oct 24, 2020

Fixes #86
added test cases
@cclauss @Parowicz @StepfenShawn

Welcome to Dart community

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 Dart files are placed inside an existing directory.
  • 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}.

@cclauss cclauss changed the title Fixes issue #86 Fix undefined_operator in fermats_little_theorem.dart Oct 24, 2020
@@ -21,12 +19,22 @@ void main() {
// a prime number
int p = 701;

double a = 1000000000;
Copy link
Member

Choose a reason for hiding this comment

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

Removing support for floating point numbers seems like a step too far. Is there a way to keep supporting floating point numbers? Tests should cover positive numbers, negative numbers, and zero as well as floating point numbers if we keep supporting them.

int b = 10;

// using binary exponentiation function, O(log(p)):
print((a / b) % p == (a * binary_exponentiation(b, p - 2, p)) % p);
Copy link
Member

Choose a reason for hiding this comment

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

Why remove this? When the visitor runs this program then nothing visible will happen. We are writing these programs primarily for readers to understand and secondarily for computers to test.

// using Python operators:
print((a / b) % p == (a * b ^ (p - 2)) % p);
Copy link
Member

Choose a reason for hiding this comment

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

Why remove this?

Added the suggested changes
Added print statements
Added support for double
fixed dart format issues
@cclauss
Copy link
Member

cclauss commented Oct 24, 2020

Tests should cover positive numbers, negative numbers, and zero as well as floating-point numbers.

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.

maths/fermats_little_theorem.dart:27:31 • undefined_operator
2 participants