Jump to content

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

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

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

Terms of Use Privacy Policy