Skip to content

Instantly share code, notes, and snippets.

@hajimehoshi
Created February 13, 2009 08:26
Show Gist options
  • Save hajimehoshi/63795 to your computer and use it in GitHub Desktop.
Save hajimehoshi/63795 to your computer and use it in GitHub Desktop.
ゼル伝
;;; ゼルダの伝説 (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