Tags
webcam vindaloo vim version vegan unix unicef trojan todo tmux thinkpad textmate testing tagging syntax svn sugar subversion stubbing sphinx spam spaces solaris sitemap site sinatra shoulda sheet set security search schema_info SchemaInfo ruby rinari restaurant relationships refresh rdiff-backup ramaze railsconf08 railsconf07 rails protools production power placeboeffect pink floyd PIC perl overheat outbreak osx os x NYHS NYC nginx netbeans nested nanophotonics mysql music MPEG-4 mongrel model migration microvolunteer macbook mac logrotate logic log linux less leopard keynote JAX javascript java jacksonville iterm2 iterm imunizator highlighting hanna Handbrake haml hacks google geocoding genghistron gem gaming gabrielle's funny functional fun friends food fixesThe Decider said over 2 years ago permalink Comment? (0)
Tagged: ruby logic
De Morgan, Ruby
#De Morgan the Ruby way
[true,false].each do |p|
[true,false].each do |q|
puts "p=#{p} q=#{q}"
if !(p or q) == (!p and !q)
puts "De Morgan Rules! !(p or q) == (!p and !q)"
else
puts "De Morgan is a Liar!"
end
# if find yourself writing
if !p and !q
print "-"
# you could be writing
unless p or q
puts "if !p and !q equivalent to unless p or q"
end
end
if !(p and q) == (!p or !q)
puts "De Morgan Rules! !(p and q) == (!p or !q)"
else
puts "De Morgan is a Liar!"
end
# if find yourself writing
if !p or !q
print "-"
# you could be writing
unless p and q
puts "if !p or !q equivalent to unless p and q"
end
end
end
end