Last active
June 25, 2022 11:16
-
-
Save shirok/7f89611e1a4b9779c3af9f89a05a5f18 to your computer and use it in GitHub Desktop.
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
;; -*- coding:utf-8 -*- | |
(use gauche.sequence) | |
(use util.match) | |
(use util.combinations) | |
(use srfi-197) ;chain | |
(define (num-fingers hands) | |
(define (f hand) (case hand | |
[(グー) 0] | |
[(チョキ) 2] | |
[(パー) 5])) | |
(apply + (map f hands))) | |
(define (num-winners hands) | |
(match (delete-duplicates hands) | |
[('グー 'チョキ) (count (cut eq? <> 'グー) hands)] | |
[('グー 'パー) (count (cut eq? <> 'パー) hands)] | |
[('チョキ 'パー) (count (cut eq? <> 'チョキ) hands)] | |
[_ 0])) | |
(define (all-decisive-hands) | |
(chain (concatenate (make-list 6 '(グー チョキ パー))) | |
(combinations* _ 6) | |
(filter-map (^[hands] (let1 n (num-winners hands) | |
(and (> n 0) | |
(list (num-fingers hands) | |
(num-winners hands))))) _) | |
(sort _ < car) | |
(delete-neighbor-dups _))) |
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
gosh> (all-decisive-hands) | |
((2 5) (4 4) (5 1) (6 3) (8 2) (10 2) (10 1) (15 3) (15 5) (18 4) (20 4) (21 3) | |
(24 2) (25 5) (27 1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment