Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
24
Task/Modular-arithmetic/Ada/modular-arithmetic.adb
Normal file
24
Task/Modular-arithmetic/Ada/modular-arithmetic.adb
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
with Ada.Text_IO;
|
||||
|
||||
procedure Modular_Demo is
|
||||
|
||||
type Modul_13 is mod 13;
|
||||
|
||||
function F (X : Modul_13) return Modul_13 is
|
||||
begin
|
||||
return X**100 + X + 1;
|
||||
end F;
|
||||
|
||||
package Modul_13_IO is
|
||||
new Ada.Text_IO.Modular_IO (Modul_13);
|
||||
|
||||
use Ada.Text_IO;
|
||||
use Modul_13_IO;
|
||||
X_Integer : constant Integer := 10;
|
||||
X_Modul_13 : constant Modul_13 := Modul_13'Mod (X_Integer);
|
||||
F_10 : constant Modul_13 := F (X_Modul_13);
|
||||
begin
|
||||
Put ("f("); Put (X_Modul_13); Put (" mod "); Put (Modul_13'Modulus'Image); Put (") = ");
|
||||
Put (F_10); Put (" mod "); Put (Modul_13'Modulus'Image);
|
||||
New_Line;
|
||||
end Modular_Demo;
|
||||
30
Task/Modular-arithmetic/R/modular-arithmetic.r
Normal file
30
Task/Modular-arithmetic/R/modular-arithmetic.r
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
as.modular <- function(x, modulus){
|
||||
if(x<0|modulus<=0) stop("both arguments must be non-negative and modulus cannot be zero")
|
||||
if(!(is.integer(x)&is.integer(modulus))) stop("both arguments must be integers")
|
||||
if(x>=modulus) x <- x%%modulus
|
||||
structure(list("num"=x, "mod"=modulus), class="modular")
|
||||
}
|
||||
|
||||
`+.modular` <- function(a, b){
|
||||
if(is.integer(b)) b <- as.modular(b, a$mod)
|
||||
if(a$mod!=b$mod) stop("arguments must have the same modulus")
|
||||
as.modular(a$num+b$num, a$mod)
|
||||
}
|
||||
|
||||
`*.modular` <- function(a, b){
|
||||
if(is.integer(b)) b <- as.modular(b, a$mod)
|
||||
if(a$mod!=b$mod) stop("arguments must have the same modulus")
|
||||
as.modular(a$num*b$num, a$mod)
|
||||
}
|
||||
|
||||
`^.modular` <- function(a, b){
|
||||
if(!is.integer(b)) stop("exponent must be an integer")
|
||||
if(b<=0) stop("exponent must be positive")
|
||||
Reduce(`*`, rep(list(a), b))
|
||||
}
|
||||
|
||||
#Need a print method to actually display modular integers
|
||||
print.modular <- function(n) cat(n$num, " (modulo ", n$mod, ")", sep="")
|
||||
|
||||
f <- function(x) x^100L+x+1L
|
||||
f(as.modular(10L, 13L))
|
||||
Loading…
Add table
Add a link
Reference in a new issue