Sha256: 9537d833b93e0de3d989c4b54c19e903583f5e81dd43c5c22f36f7c79c8478d3
Contents?: true
Size: 629 Bytes
Versions: 1
Compression:
Stored size: 629 Bytes
Contents
require 'sperm/groups/intmod' module Sperm::Groups # Represents (Z/nZ, +) - an additive cyclic group of integers modulo n. # class ZnAdd include Zn attr_reader :modulo alias_method :order, :modulo def initialize(modulo_factors) @modulo_factors = modulo_factors.uniq @modulo = modulo_factors.inject(1, &:*) end def generator?(number) fail ArgumentError, 'not an element' unless include?(number) @modulo_factors.all? { |prime| coprime_with_prime?(number, prime) } end private def coprime_with_prime?(number, prime) number % prime != 0 end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sperm-0.1.1 | lib/sperm/groups/additive.rb |