The 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

Comments

simple_captcha.jpg
Are you a Human? Type the code above.