Sha256: b2a38c35bbb9937ccac7ab87b097b7769f83444b6fdef59f9d43e7a84a8da44c
Contents?: true
Size: 596 Bytes
Versions: 5
Compression:
Stored size: 596 Bytes
Contents
# coding: utf-8 class Integer def segmented return self if self <= 2 this = ((n = self)-1).segmented.succ sum = Hash.new{|h, k| h[k] = k.map(&:segmented).reduce(:+) } priors_sum = ->(target) do (n - 2).downto(1).any? do |start| (start.succ..(n-1)).any? do |stop| break if (s = sum[ start..stop ]) > target s == target end end end this += 1 while priors_sum[ this ] this end memoize :segmented def segmented? in_sequence?(seq: :segmented) end alias :prime_number_of_measurement? :segmented? end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
numb-0.186.0 | lib/numb/segmented.rb |
numb-0.185.0 | lib/numb/segmented.rb |
numb-0.184.0 | lib/numb/segmented.rb |
numb-0.181.0 | lib/numb/segmented.rb |
numb-0.170.0 | lib/numb/segmented.rb |