Jump to content
Sign in to follow this  
AM

logikgatter / logic gates (completed)

Recommended Posts

complementation to OR/AND/NOT! i hope everything is correct...

https://de.wikipedia.org/wiki/Logikgatter

 

(defun nand (&rest rest)
  (flet ((every-truep (x)
           (equal x t)))
    (not (every #'every-truep rest))))

(nand nil nil nil)
=> t
(nand t t t t t t)
=> nil
(nand nil t t t nil t)
=> t


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(defun nor (&rest rest)
  (contain-itemp 'nil rest))

(nor t t t t)
=> nil
(nor nil t nil)
=> t
(nor t nil nil nil)
=> t


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun xor (&rest rest)
  (oddp (car (count-item t rest))))

(xor t nil t t nil nil nil) 
=> t
(xor t t nil)
=> nil 
(xor nil t)
=> t

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun xnor (&rest rest)
  (evenp (car (count-item t rest))))

(xnor t nil t t nil nil nil)
=> nil
(xnor t t nil)
=> t 
(xnor nil t)
=> nil
(xnor t nil t t nil nil t nil)
=> t

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×