Skip to content

Instantly share code, notes, and snippets.

@ryukinix
Created December 2, 2022 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryukinix/e63459d402d26d67e69c093d1b3a46f4 to your computer and use it in GitHub Desktop.
Save ryukinix/e63459d402d26d67e69c093d1b3a46f4 to your computer and use it in GitHub Desktop.
paper scissors rock written in loop
;; 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