Created
October 7, 2012 06:21
-
-
Save samrat/3847295 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
(define cutA 7) | |
(define growA 3) | |
(define cutB 5) | |
(define growB 2) | |
(define (attack-monster heads) | |
(use-sword heads 0 '())) | |
(define (use-sword n grow s) | |
(cond ((< n 0) '()) | |
((= n 0) | |
;(print s) | |
;(newline) | |
(list s)) | |
(else | |
(append | |
(use-sword | |
(- (+ n grow) cutA) | |
growA | |
(append s (list 'a))) | |
(use-sword | |
(- (+ n grow) cutB) | |
growB | |
(append s (list 'b))))))) | |
(define (shortest-way heads) | |
(first (sort (attack-monster heads) (lambda (x y) (< (length x) (length y)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment