Skip to content

Instantly share code, notes, and snippets.

@colomon
Created October 6, 2014 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colomon/3a2861c1b9e492836b75 to your computer and use it in GitHub Desktop.
Save colomon/3a2861c1b9e492836b75 to your computer and use it in GitHub Desktop.
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