tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
28
Task/Playing-cards/Scheme/playing-cards-1.ss
Normal file
28
Task/Playing-cards/Scheme/playing-cards-1.ss
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
(define ranks
|
||||
(quote (ace 2 3 4 5 6 7 8 9 10 jack queen king)))
|
||||
|
||||
(define suits
|
||||
(quote (clubs diamonds hearts spades)))
|
||||
|
||||
(define new-deck
|
||||
(apply append
|
||||
(map (lambda (suit)
|
||||
(map (lambda (rank)
|
||||
(cons rank suit))
|
||||
ranks))
|
||||
suits)))
|
||||
|
||||
(define (shuffle deck)
|
||||
(define (remove-card deck index)
|
||||
(if (zero? index)
|
||||
(cdr deck)
|
||||
(cons (car deck) (remove-card (cdr deck) (- index 1)))))
|
||||
(if (null? deck)
|
||||
(list)
|
||||
(let ((index (random (length deck))))
|
||||
(cons (list-ref deck index) (shuffle (remove-card deck index))))))
|
||||
|
||||
(define-syntax deal!
|
||||
(syntax-rules ()
|
||||
((deal! deck hand)
|
||||
(begin (set! hand (cons (car deck) hand)) (set! deck (cdr deck))))))
|
||||
14
Task/Playing-cards/Scheme/playing-cards-2.ss
Normal file
14
Task/Playing-cards/Scheme/playing-cards-2.ss
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
(define deck
|
||||
(shuffle new-deck))
|
||||
|
||||
(define hand
|
||||
(list))
|
||||
|
||||
(deal! deck hand)
|
||||
(deal! deck hand)
|
||||
(deal! deck hand)
|
||||
(deal! deck hand)
|
||||
(deal! deck hand)
|
||||
|
||||
(display hand)
|
||||
(newline)
|
||||
Loading…
Add table
Add a link
Reference in a new issue