Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
22
Task/Modular-arithmetic/ALGOL-68/modular-arithmetic.alg
Normal file
22
Task/Modular-arithmetic/ALGOL-68/modular-arithmetic.alg
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
# allow for large integers in Algol 68G #
|
||||
PR precision 200 PR
|
||||
|
||||
# modular integer type #
|
||||
MODE MODULARINT = STRUCT( LONG LONG INT v, INT modulus );
|
||||
|
||||
# modular integer + and * operators #
|
||||
# where both operands are modular, they must have the same modulus #
|
||||
OP + = ( MODULARINT a, b )MODULARINT: ( ( v OF a + v OF b ) MOD modulus OF a, modulus OF a );
|
||||
OP + = ( MODULARINT a, INT b )MODULARINT: ( ( v OF a + b ) MOD modulus OF a, modulus OF a );
|
||||
OP * = ( MODULARINT a, b )MODULARINT: ( ( v OF a * v OF b ) MOD modulus OF a, modulus OF a );
|
||||
OP ** = ( MODULARINT a, INT b )MODULARINT: ( ( v OF a ** b ) MOD modulus OF a, modulus OF a );
|
||||
|
||||
# f(x) function - can be applied to either LONG LONG INT or MODULARINT values #
|
||||
# the result is always a LONG LONG INT #
|
||||
PROC f = ( UNION( LONG LONG INT, MODULARINT ) x )LONG LONG INT:
|
||||
CASE x
|
||||
IN ( LONG LONG INT ix ): ( ix**100 + ix + 1 )
|
||||
, ( MODULARINT mx ): v OF ( mx**100 + mx + 1 )
|
||||
ESAC;
|
||||
|
||||
print( ( whole( f( MODULARINT( 10, 13 ) ), 0 ), newline ) )
|
||||
Loading…
Add table
Add a link
Reference in a new issue