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
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions maths/fermats_little_theorem.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
@Skip('currently failing (see issue #86)')

import 'package:test/test.dart';
import 'dart:math';

/*
Fermat's little Theorem
Translated from TheAlgorithms/Python
*/
Fermat's little Theorem
Translated from TheAlgorithms/Python
*/
binary_exponentiation(a, n, mod) {
if (n == 0) {
return 1;
Expand All @@ -25,8 +24,20 @@ void main() {
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.


print((a / b) % p == (a * binary_exponentiation(b, p - 2, p) % p));
print((a / b) % p == (a * pow(b, (p - 2)) % p));
test(
'test 1',
() {
expect(
(a / b) % p == (a * binary_exponentiation(b, p - 2, p) % p), isTrue);
},
);
// 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?

test(
'test 2',
() {
expect((a / b) % p == (a * pow(b, (p - 2)) % p), isFalse);
},
);
}