Modular Inverse unittest

Back to Problem Solutions forum

Moff     2014-08-11 11:18:31
User avatar

Modular Inverse problem accepts solution for modular equation:

B * x - A = 0 | mod M

instead of:

A * x + B = 0 | mod M

For first unittest from example:

M, A, B, x = 929, 252, 410, 413
(A * x + B) % m = 438
(B * x - A) % m = 0

For third unittest from example:

M, A, B, x = 705, 77, 443, 589
(A * x + B) % m = 676
(B * x - A) % m = 0
Rodion (admin)     2014-08-11 12:46:08
User avatar

Oh, I see I've made a horrible mistake in formula when trying to refactor it! I'll fix it soon.

Quite curious, how you anyway got to solve this "puzzle" :D

Moff     2014-08-11 12:49:30
User avatar

Quite curious, how you anyway got to solve this "puzzle" :D

TDD is my way :)

I'll wait the proper checker and then try to solve it again.

nicolas_patrois     2014-08-11 13:00:03
User avatar

GCD(494,235)=1, the second example of 144 seems buggy.

Rodion (admin)     2014-08-11 13:04:51
User avatar

> TDD is my way :)

You are invaluable specialist! I wish my colleagues share your views! :)

> GCD(494,235)=1, the second example of 144 seems buggy.

I'm afraid they all were completely wrong. Thanks to hint by Serge I've fixed it just now (I hope).

nicolas_patrois     2014-08-11 13:16:40
User avatar

OK.

Have you checked the checker, too?

Rodion (admin)     2014-08-11 13:30:26
User avatar

Yes, the bug was in the checker itself and the first version of "example" was generated with it also with bugs.

Since I've fixed them both I think the first solution by Serge should work no more :)

Do you suspect the bug in checker still exists?

nicolas_patrois     2014-08-11 13:49:40
User avatar

No, I think that it’s correct now.

Moff     2014-08-11 13:57:03
User avatar

I've submitteded the proper solution for ax+b=0. It works.

But in page http://www.codeabbey.com/index/task_solvers/modular-inverse i see two solutions of Nicolas.

  1. MoffSerge (Python)
  2. nicolas_patrois (Python)
  3. nicolas_patrois (Ruby)
Rodion (admin)     2014-08-11 15:46:34
User avatar

Yes, it is just a buggy "feature" of our site - several solutions in different languages could be saved (though only one is counted). However Python is sometimes incorrectly detected as Ruby so the same solution in Python could give "two" in these two languages... I know it looks silly %)

nicolas_patrois     2014-08-11 15:55:31
User avatar

My codes always begin with the shebang (you can add this in your detector).

Please login and solve 5 problems to be able to post at forum