Skip to content

Instantly share code, notes, and snippets.

@shuzo-kino
Created October 5, 2013 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shuzo-kino/6838628 to your computer and use it in GitHub Desktop.
Save shuzo-kino/6838628 to your computer and use it in GitHub Desktop.
再帰処理による真理値表((b0 || b1 && !b2)) 習作 元ネタ:再帰の技法 基本的考え方・アルゴリズム・プログラミング(ISBN-13: 978-4434085970)
$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