fork download
  1. (defconstant G 1 "Goo (rock)")
  2. (defconstant C 2 "Choki (scissor)")
  3. (defconstant P 4 "Paa (paper)")
  4.  
  5. (defun janken-winner (hands)
  6. (let ((x (apply #'logior hands)))
  7. (cond ((eql x (logior G C)) G)
  8. ((eql x (logior C P)) C)
  9. ((eql x (logior P G)) P)
  10. (t nil))))
  11.  
  12. (defun janken-count-winners (hands)
  13. (let ((win (janken-winner hands)))
  14. (values (count win hands) win)))
  15.  
  16. (defun janken-format-hand (stream arg colon atsign)
  17. (declare (ignore colon atsign))
  18. (princ (cond ((eql arg G) #\g)
  19. ((eql arg C) #\c)
  20. ((eql arg P) #\p)
  21. (t (error "Not a JANKEN hand: ~S" arg)))
  22. stream))
  23.  
  24. (let ((games (list (list g c c g c)
  25. (list g g g g g g g)
  26. (list c p p c p p p p c c p p p p p c)
  27. (list c p p c p p p p c c p g p p p c))))
  28. (dolist (hands games)
  29. (format t "~{~/janken-format-hand/~} -> ~D~%"
  30. hands (janken-count-winners hands))))
  31.  
Success #stdin #stdout 0.01s 26932KB
stdin
Standard input is empty
stdout
gccgc -> 2
ggggggg -> 0
cppcppppccpppppc -> 5
cppcppppccpgpppc -> 0