Created
April 22, 2017 18:42
-
-
Save LeifAndersen/fd5ed51648ccb8fd8568903cef247633 to your computer and use it in GitHub Desktop.
flush
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
| #lang racket/base | |
| (require racket/set | |
| racket/list) | |
| (define (P event space) | |
| (/ (for/fold ([acc 0]) | |
| ([x (in-list space)] | |
| #:when (event x)) | |
| (add1 acc)) | |
| (length space))) | |
| (define (cross A B) | |
| (for*/list ([a (in-string A)] | |
| [b (in-string B)]) | |
| (cons a b))) | |
| (define suits "SHDC") | |
| (define ranks "A23456789TJQK") | |
| (define deck (cross ranks suits)) | |
| (define Hands (combinations deck 5)) | |
| (define (flush hand) | |
| (for/or ([suit (in-string suits)]) | |
| (for/and ([card (in-list hand)]) | |
| (equal? suit (cdr card))))) | |
| (time | |
| (displayln (P flush Hands))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment