Class: Natural::Prep
- Inherits:
-
Object
- Object
- Natural::Prep
- Defined in:
- lib/m500.rb
Instance Attribute Summary collapse
-
#max ⇒ Object
Returns the value of attribute max.
-
#prep ⇒ Object
Returns the value of attribute prep.
Instance Method Summary collapse
- #deltaNextPrime ⇒ Object
- #equivClassChck(s) ⇒ Object
-
#initialize(int) ⇒ Prep
constructor
A new instance of Prep.
- #next ⇒ Object
- #nextP(s) ⇒ Object
Constructor Details
#initialize(int) ⇒ Prep
Returns a new instance of Prep.
884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 |
# File 'lib/m500.rb', line 884 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
#max ⇒ Object
Returns the value of attribute max.
900 901 902 |
# File 'lib/m500.rb', line 900 def max @max end |
#prep ⇒ Object
Returns the value of attribute prep.
900 901 902 |
# File 'lib/m500.rb', line 900 def prep @prep end |
Instance Method Details
#deltaNextPrime ⇒ Object
927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 |
# File 'lib/m500.rb', line 927 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
918 919 920 921 922 923 924 925 926 |
# File 'lib/m500.rb', line 918 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 |
#next ⇒ Object
906 907 908 909 910 911 912 913 914 915 916 917 |
# File 'lib/m500.rb', line 906 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
963 964 965 |
# File 'lib/m500.rb', line 963 def nextP(s) return s + deltaNextPrime end |