Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -0,0 +1,11 @@
package Mod_Inv is
procedure X_GCD(A, B: in Natural; D, X, Y: out Integer);
-- the Extended Euclidean Algorithm
-- finds (D, X, Y) with D = GCD(A, B) = A*X + B*Y
function Inverse(A, M: Integer) return Integer;
-- computes the multiplicative inverse Inv_A of A mod M, using X_GCD
-- raises Constraint_Error if Inv_A does not exist
end Mod_Inv;

View file

@ -1,6 +1,4 @@
with Ada.Text_IO;
procedure Mod_Inv is
package body Mod_Inv is
procedure X_GCD(A, B: in Natural; D, X, Y: out Integer) is
-- the Extended Euclidean Algorithm
@ -35,8 +33,4 @@ procedure Mod_Inv is
end if;
end Inverse;
begin
Ada.Text_IO.Put_Line(Natural'Image(Inverse(42, 2017)));
-- Ada.Text_IO.Put_Line(Natural'Image(Inverse(154, 3311)));
-- The above would raise CONSTRAINT_ERROR : GCD ( 154, 3311 ) = 77 /= 1
end Mod_Inv;

View file

@ -0,0 +1,9 @@
with Ada.Text_IO; with Mod_Inv; use Mod_Inv, Ada.text_IO;
procedure Mod_Inv_Test is
begin
-- Put_Line(Natural'Image(Inverse(154, 3311)));
-- The above would raise CONSTRAINT_ERROR : GCD ( 154, 3311 ) = 77 /= 1
Put_Line(Natural'Image(Inverse(42, 2017)));
end Mod_Inv_Test;