Class: Natural::Prep

Inherits:
Object
  • Object
show all
Defined in:
lib/m500.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(int) ⇒ Prep

Returns a new instance of Prep.



954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
# File 'lib/m500.rb', line 954

def initialize(int)
  @comp = int
  @prep = []
  @max = 50000
  b = []
  @prms = Prime.each(@max){|a| b << a}
  b = nil
  Prime.each(int){|a|
    moduli = int.modulo(a)
    power = 0
    b  = int.divmod(a)
    power =  (int/b.at(0))/a if b.at(1) == 0
    moduli = [power] if moduli == 0
    @prep << moduli
  }
end

Instance Attribute Details

#maxObject

Returns the value of attribute max.



970
971
972
# File 'lib/m500.rb', line 970

def max
  @max
end

#prepObject

Returns the value of attribute prep.



970
971
972
# File 'lib/m500.rb', line 970

def prep
  @prep
end

Instance Method Details

#deltaNextPrimeObject



997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
# File 'lib/m500.rb', line 997

def deltaNextPrime
  a = nil
  res=[]
  r =[]
  r0=[]
  r1=0 
  @prep.each_index{|x|
    if @prep.at(x).class == Array then
      t = "0 + #{@prms.at(x)}*k"
    else # @prep.at(x).class == Numeric
      t = "#{@prms.at(x)-@prep.at(x)}+(#{@prms.at(x)}*k)"
    end
    r << t
  }
  m = @prms.at(@prep.length-1)
  rz = 0
  rx = []
  r.each{|r4|
    rx << eval("k=0;#{r4}") }
  ry =  rx.max
  (0..m).to_a.each{|k|
    r.each{|r4|
      r0 << eval("k=#{k};#{r4}")
    }
    rz= r0.max
    res = res + r0
    r0=[]
    if ry < rz then
      a = equivClassChck(res.to_s)
      break unless a.nil?
      ry = rz
    else
    end
  }
  a 
end

#equivClassChck(s) ⇒ Object



988
989
990
991
992
993
994
995
996
# File 'lib/m500.rb', line 988

def equivClassChck(s)
  r = Array.new
  r = eval(s)
  r = r.uniq
  r = r.sort
  r.collect!{|i| i == r.find_index(i) ? nil : r.find_index(i)}
  r = r.compact
  r.at(0)
end

#nextObject



976
977
978
979
980
981
982
983
984
985
986
987
# File 'lib/m500.rb', line 976

def next
  b = @prms
  t =[]
  @prep.each_index{|a|
    t[a] = 1  if @prep.at(a).class == Array
    z = (@prep.at(a) + 1).modulo(b.at(a)) unless @prep.at(a).class == Array
    z = [((@comp+1)/(@comp+1).divmod(b.at(a)).at(0))/b.at(a)] if z == 0
    t[a] = z unless @prep.at(a).class == Array
  }
  t << [1] if t == t.flatten
  return t
end

#nextP(s) ⇒ Object



1033
1034
1035
# File 'lib/m500.rb', line 1033

def nextP(s)
  return s + deltaNextPrime
end