Last active
December 14, 2015 00:49
-
-
Save ayato-p/5001488 to your computer and use it in GitHub Desktop.
ドラクエVIIのバロックタワーのパズルを解く
( http://d.hatena.ne.jp/torazuka/20130221/ddd )
を参考に問いてみたけど、出力結果が思うようにいかない…。
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
(define (baroque input) | |
(define (ok? ls) | |
(let ((model-1 (list-ref ls 0)) | |
(model-2 (list-ref ls 1)) | |
(model-3 (list-ref ls 2)) | |
(model-4 (list-ref ls 3))) | |
(and (= model-1 2) | |
(= model-2 3) | |
(= model-3 0) | |
(= model-4 1)))) | |
(define (next x) | |
(let ((next-x (+ x 1))) | |
(if (= next-x 4) | |
0 | |
next-x))) | |
(define (push n ls) | |
(let loop ((m (next n)) | |
(count 0) | |
(ls ls) | |
(out '())) | |
(cond | |
((null? ls) (reverse out)) | |
((= count m) | |
(loop m | |
(+ count 1) | |
(cdr ls) | |
(cons (car ls) out))) | |
(else | |
(loop m | |
(+ count 1) | |
(cdr ls) | |
(cons (next (car ls)) out)))))) | |
(let loop ((count 0) | |
(max 8) | |
(input input) | |
(output '())) | |
(cond | |
((> count max) '()) | |
((ok? input) | |
(reverse output)) | |
(else | |
(list (loop (+ count 1) | |
max | |
(push 0 input) | |
(cons 0 output)) | |
(loop (+ count 1) | |
max | |
(push 1 input) | |
(cons 1 output)) | |
(loop (+ count 1) | |
max | |
(push 2 input) | |
(cons 2 output)) | |
(loop (+ count 1) | |
max | |
(push 3 input) | |
(cons 3 output))))))) | |
(baroque '(3 2 2 3)) | |
;; ex. | |
;; input '(3 2 2 3) | |
;; output '(0 0 0 1 1 2 2 3) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment