Skip to content

Instantly share code, notes, and snippets.

@shirok
Last active June 25, 2022 11:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shirok/7f89611e1a4b9779c3af9f89a05a5f18 to your computer and use it in GitHub Desktop.
Save shirok/7f89611e1a4b9779c3af9f89a05a5f18 to your computer and use it in GitHub Desktop.
;; -*- 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 _)))
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