Created
February 13, 2009 08:26
-
-
Save hajimehoshi/63795 to your computer and use it in GitHub Desktop.
ゼル伝
This file contains 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
;;; ゼルダの伝説 (SFC) で、鍵と扉がそれぞれ n 個のとき、 | |
;;; ダンジョンのとりうる状態数を返す zelda 関数 (仮) | |
(use srfi-1) | |
(define (zelda n) | |
(define (combination n m) | |
(/ (apply * (iota m (+ (- n m) 1) 1)) | |
(apply * (iota m 1 1)))) | |
(define (sum list) | |
(apply + list)) | |
(sum (map (lambda (k) | |
(* (combination n k) | |
(sum (map (cut combination n <>) | |
(iota (+ k 1)))))) | |
(iota (+ n 1))))) | |
(define (main args) | |
(print (zelda (string->number (cadr args))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment