Class: QuineMc::Quine_McClusky

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

Instance Method Summary collapse

Constructor Details

#initialize(m, d) ⇒ Quine_McClusky

Returns a new instance of Quine_McClusky.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/quine_mc.rb', line 7

def initialize(m, d)
	@nl = find_num_lit(m, d)
	if (m+d) == (0..2**(@nl)-1).to_a or (m+d).empty?
		@sop = []
		@pos = []
	else
		maxterms = (0...2**@nl).to_a - (m+d)
		@sop = EPi_List.new(m, d, @nl)
		@pos = EPi_List.new(maxterms, d, @nl)
	end
end

Instance Method Details

#display_solObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/quine_mc.rb', line 23

def display_sol
	if !@sop.empty? and !@pos.empty?
		print "f = "
		@sop.each do |t|
			print (t == @sop.last)? t.to_prod(@nl) : t.to_prod(@nl)+" + " 
		end
		puts
		print "f = "
		@pos.each do |t|
			print t.to_sum(@nl)
		end
		puts
	else
		puts "f = 1"
	end
end

#find_num_lit(m, d) ⇒ Object



19
20
21
# File 'lib/quine_mc.rb', line 19

def find_num_lit(m, d)
	return (m+d).max.to_s(2).size
end