Class: QuineMc::Cube
- Inherits:
-
Array
- Object
- Array
- QuineMc::Cube
- Defined in:
- lib/quine_mc/cube.rb
Instance Method Summary collapse
Instance Method Details
#num_ones ⇒ Object
4 5 6 7 8 9 |
# File 'lib/quine_mc/cube.rb', line 4 def num_ones n = inject {|m,o| m & o} count = 0 count += n & 1 and n >>= 1 until n == 0 return count end |
#strict_subset?(b) ⇒ Boolean
34 35 36 |
# File 'lib/quine_mc/cube.rb', line 34 def strict_subset?(b) self & b == self and length < b.length end |
#to_prod(n_l) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/quine_mc/cube.rb', line 11 def to_prod(n_l) ls = (n_l > 26)? (0..n_l).to_a.map {|n| n = "A" << n.to_s} : ('A'..'Z').to_a[0,n_l] p = "" ls.each_with_index do |l, i| if all? {|x| first[n_l-i-1] == x[n_l-i-1]} p << (first[n_l-i-1] == 1 ? l : l+"'") end end return p end |
#to_sum(n_l) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/quine_mc/cube.rb', line 22 def to_sum(n_l) ls = (n_l > 26)? (0..n_l).to_a.map {|n| n = "A" << n.to_s} : ('A'..'Z').to_a[0,n_l] s = "(" ls.each_with_index do |l, i| if all? {|x| first[n_l-i-1] == x[n_l-i-1]} s << (first[n_l-i-1] == 1 ? l+"'+" : l+"+") end end s[s.size-1] = ")" return s end |