ここで聞くのはもったいないです。本当にそうです。悩みの答えを無駄に探すたびに、それが見えてきます。私を罵倒します。スタック オーバーフロー。
とにかく、地獄のような影響を受けて、ハノイの塔を解決しようとしました。あまりにも多くのディスクで実行するとメモリ エラーが発生したため、最初の解決策は不完全でした。
(define hanoi
(lambda (n from to other)
(cond ((< n 0)
(error `(Error! Number of disks ,n cannot be less than 0!)))
((= n 0)
'())
(else
(append (hanoi (- n 1)
from
other
to)
`((,from ,to))
(hanoi (- n 1)
other
to
from))))))
継続渡しスタイルが問題を解決するということをどこかで読みました。ただし、これも役に立ちませんでした:
(define hanoi_cps
(lambda (n from to other c)
(cond ((< n 0)
(error `(Error! Number of disks ,n cannot be less than 0!)))
((= n 0)
(c '()))
(else
(hanoi_cps (- n 1)
from
other
to
(lambda (x)
((lambda (w)
(w `((,from ,to))))
(lambda (y)
(hanoi_cps (- n 1)
other
to
from
(lambda (z)
(c (append x y z))))))))))))