Skip to content

Instantly share code, notes, and snippets.

@rrguntaka
Created November 15, 2011 21:30
Show Gist options
  • Save rrguntaka/1368418 to your computer and use it in GitHub Desktop.
Save rrguntaka/1368418 to your computer and use it in GitHub Desktop.
Propositional Logic - AI Class - Truth Table
def implies(a,b)
!(a & !b)
end
def str(a)
a.to_s[0].upcase
end
def printTable
all = [false,true]
all.product(all).each{|a,b|
puts "#{str(a)} #{str(b)} #{str(yield(a,b))}"
}
puts
end
printTable {|a,b| implies(a,b)}
printTable {|a,b| (a | !b)}
printTable {|a,b| implies(!a,!b)}
printTable {|a,b| implies(!b,!a)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment