Skip to content

Instantly share code, notes, and snippets.

@LeifAndersen
Created April 22, 2017 18:42
Show Gist options
  • Select an option

  • Save LeifAndersen/fd5ed51648ccb8fd8568903cef247633 to your computer and use it in GitHub Desktop.

Select an option

Save LeifAndersen/fd5ed51648ccb8fd8568903cef247633 to your computer and use it in GitHub Desktop.
flush
#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