Created
October 5, 2013 09:08
-
-
Save shuzo-kino/6838628 to your computer and use it in GitHub Desktop.
再帰処理による真理値表((b0 || b1 && !b2)) 習作 元ネタ:再帰の技法 基本的考え方・アルゴリズム・プログラミング(ISBN-13: 978-4434085970)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$b = [] | |
NUM = 3 | |
def truth_table(k) | |
if k < NUM | |
$b[k] = false | |
truth_table(k+1) | |
$b[k] = true | |
truth_table(k+1) | |
else | |
printAry | |
end | |
end | |
def printAry() | |
$b.each do |i| | |
i == true ? i = 'T' : i = 'F' | |
print "\t" + i.to_s + "," | |
end | |
puts $b[0] || $b[1] && !$b[2] ? "\tT" : "\tF" | |
end | |
puts <<EOS | |
\tb0,\tb1,\tb2,\t(b0 || b1 && !b2) | |
\t**************************************** | |
EOS | |
p truth_table(0) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment