Created
October 6, 2014 13:34
-
-
Save colomon/3a2861c1b9e492836b75 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ModuloInteger { | |
has Int $.N; | |
has Int $.value; | |
} | |
multi sub infix:<+>(ModuloInteger $a, Int $b) { | |
ModuloInteger.new(N => $a.N, value => ($a.value + $b) % $a.N) | |
} | |
multi sub infix:<+>(Int $b, ModuloInteger $a) { | |
ModuloInteger.new(N => $a.N, value => ($a.value + $b) % $a.N) | |
} | |
multi sub infix:<+>(ModuloInteger $a, ModuloInteger $b) { | |
die unless $a.N == $b.N; | |
ModuloInteger.new(N => $a.N, value => ($a.value + $b.value) % $a.N) | |
} | |
sub Z(Int $N) { | |
-> $value { | |
ModuloInteger.new(N => $N, value => $value) | |
} | |
} | |
constant &Z11 = Z(11); | |
use Test; | |
my @a = ModuloInteger.new(N => 11, value => 0), * + 2 ... *.value == 9; | |
say @a; | |
my @b = Z11(0), * + 2 ... *.value == 9; | |
say @b; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment