Skip to content

Instantly share code, notes, and snippets.

@masaedw
Forked from hajimehoshi/gist:63795
Created February 13, 2009 08:38
Show Gist options
  • Save masaedw/63802 to your computer and use it in GitHub Desktop.
Save masaedw/63802 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 (+ (- n 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