Created
December 2, 2022 20:21
-
-
Save ryukinix/e63459d402d26d67e69c093d1b3a46f4 to your computer and use it in GitHub Desktop.
paper scissors rock written in loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Then, a winner for that round is selected: Rock defeats Scissors, | |
;; Scissors defeats Paper, and Paper defeats Rock. If both players | |
;; choose the same shape, the round instead ends in a draw. | |
(defun winner (a b) | |
(loop with hands = (cons a b) | |
and rules = '(((paper . scissors) second) | |
((paper . rock) first) | |
((rock . paper) second) | |
((rock . scissors) first) | |
((scissors . paper) first) | |
((scissors . rock) second)) | |
for (rule answer) in rules | |
when (equalp rule hands) | |
do (return answer) | |
finally (return 'draw))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment