class Natural::Prep

Attributes

max[RW]
prep[RW]

Public Class Methods

new(int) click to toggle source
# File lib/m500.rb, line 951
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

Public Instance Methods

deltaNextPrime() click to toggle source
# File lib/m500.rb, line 994
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 << instance_eval("k=0;#{r4}") }
  ry =  rx.max
  (0..m).to_a.each{|k|
    r.each{|r4|
      r0 << instance_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) click to toggle source
# File lib/m500.rb, line 985
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
max=(m = 500000) click to toggle source
# File lib/m500.rb, line 968
def max=(m = 500000)
  b = []
  @max = m
  @prms = Prime.each(@max){|a| b << a}
end
next() click to toggle source
# File lib/m500.rb, line 973
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) click to toggle source
# File lib/m500.rb, line 1030
def nextP(s)
  return s + deltaNextPrime
end