(define ranks '(a k q j 10 9 8 7 6 5 4 3 2))

(define suits '(s h d c))

(define (numeric-rank rank)

   (cond ((equal? rank 'a) 14)

         ((equal? rank 'k) 13)

         ((equal? rank 'q) 12)

         ((equal? rank 'j) 11)

         (else rank)))

(define (make-card suit rank)

   (word suit rank))

(define (rank card) (bf card))

(define (suit card) (first card))



(define (sort hand)

   ((repeated sort-once (- (count hand) 1)) hand))



(define (sort-once hand)

   (cond ((empty? hand) hand)

         ((= (count hand) 1) hand)

         ((> (numeric-rank (bf (first hand)))

             (numeric-rank (bf (first (bf hand)))))

                 (se (first hand) (sort-once (bf hand))))

         (else (se (first (bf hand))

                   (sort-once (se (first hand) (bf (bf hand))))))))



(define (poker-value hand)

  (let ((sortedhand (sort hand)))

    (cond ((royal-flush? sortedhand) ??)

          ((straight-flush? sortedhand) ??)

          ((four-of-a-kind? sortedhand) ??)

          ((full-house? sortedhand) ??)

          ((flush? sortedhand) ??)

          ((straight? sortedhand) ??)

          ((three-of-a-kind? sortedhand) ??)

          ((two-pair? sortedhand) ??)

          ((pair? sortedhand) ??)

          (else ??))))