Playing cards: Difference between revisions
Content added Content deleted
Cyril Nocton (talk | contribs) |
Cyril Nocton (talk | contribs) No edit summary |
||
Line 2,113: | Line 2,113: | ||
(declare (ignore x y)) |
(declare (ignore x y)) |
||
(zerop (random 2)))))</syntaxhighlight> |
(zerop (random 2)))))</syntaxhighlight> |
||
====Alternative version==== |
|||
1. Program |
|||
<syntaxhighlight lang="lisp>;; 22.10.28 |
|||
(defconstant +pips+ '(ace 2 3 4 5 6 7 8 9 10 jack queen king)) |
|||
(defconstant +suits+ '(club diamond heart spade)) |
|||
(defvar *deck* nil) |
|||
(defun make-deck () |
|||
(loop for p in +pips+ append (loop for s in +suits+ collect (list p s)))) |
|||
(defun shuffle-deck (deck) |
|||
(loop repeat 1024 do |
|||
(rotatef (nth (random 52) deck) (nth (random 52) deck))))</syntaxhighlight> |
|||
2. Execution |
|||
<pre>(setf *deck* (make-deck)) |
|||
(shuffle-deck *deck*)</pre> |
|||
{{out}} |
|||
<pre>((ACE CLUB) (ACE DIAMOND) (ACE HEART) (ACE SPADE) (2 CLUB) (2 DIAMOND) |
|||
(2 HEART) (2 SPADE) (3 CLUB) (3 DIAMOND) (3 HEART) (3 SPADE) (4 CLUB) |
|||
(4 DIAMOND) (4 HEART) (4 SPADE) (5 CLUB) (5 DIAMOND) (5 HEART) (5 SPADE) |
|||
(6 CLUB) (6 DIAMOND) (6 HEART) (6 SPADE) (7 CLUB) (7 DIAMOND) (7 HEART) |
|||
(7 SPADE) (8 CLUB) (8 DIAMOND) (8 HEART) (8 SPADE) (9 CLUB) (9 DIAMOND) |
|||
(9 HEART) (9 SPADE) (10 CLUB) (10 DIAMOND) (10 HEART) (10 SPADE) (JACK CLUB) |
|||
(JACK DIAMOND) (JACK HEART) (JACK SPADE) (QUEEN CLUB) (QUEEN DIAMOND) |
|||
(QUEEN HEART) (QUEEN SPADE) (KING CLUB) (KING DIAMOND) (KING HEART) |
|||
(KING SPADE)) |
|||
((8 DIAMOND) (4 SPADE) (7 DIAMOND) (ACE DIAMOND) (10 HEART) (7 CLUB) (6 SPADE) |
|||
(9 HEART) (JACK CLUB) (JACK DIAMOND) (3 SPADE) (7 HEART) (KING HEART) |
|||
(4 DIAMOND) (QUEEN SPADE) (6 HEART) (10 SPADE) (QUEEN HEART) (3 DIAMOND) |
|||
(2 SPADE) (8 CLUB) (2 DIAMOND) (4 CLUB) (6 CLUB) (9 SPADE) (6 DIAMOND) |
|||
(JACK SPADE) (2 HEART) (2 CLUB) (10 DIAMOND) (4 HEART) (JACK HEART) |
|||
(ACE SPADE) (KING SPADE) (5 HEART) (5 CLUB) (7 SPADE) (ACE CLUB) (9 CLUB) |
|||
(9 DIAMOND) (ACE HEART) (8 SPADE) (8 HEART) (10 CLUB) (3 CLUB) (KING DIAMOND) |
|||
(KING CLUB) (5 DIAMOND) (3 HEART) (QUEEN CLUB) (QUEEN DIAMOND) (5 SPADE))</pre> |
|||
That's all Folks ! |
|||
''cyril nocton (cyril.nocton@gmail.com) w/ google translate'' |
|||
=={{header|D}}== |
=={{header|D}}== |
||
<syntaxhighlight lang="d">import std.stdio, std.typecons, std.algorithm, std.traits, std.array, |
<syntaxhighlight lang="d">import std.stdio, std.typecons, std.algorithm, std.traits, std.array, |