|
|
||
今度は迷路の自動生成(とその解き方)(http://www.rubyquiz.com/quiz31.html)。
All nodes of the maze must be reachable from any point.
まず全てのノードに到達できるようにすること。これは生成後に移動可能な場所をチェックして、いっていないところがあったら穴をあけることで解決した。
Furthermore, let us enforce that only 1 viable solution for the maze exists for any given start/stop (you cannot reach the same destination from 2 different routes).
もう1つ注意点。ただ1つの解になるようにすること、ということなので環ができていたら埋めてみました。
Greg2007/02/05 03:59If you wanna stop guestbook spammers just confirm url of this page to anti.spam.police@gmail.com with subject:ANTISPAM. Thx.
Greg Nilson2007/02/05 16:55If you wanna stop guestbook spammers just confirm url of this page to anti.spam.police@gmail.com with subject:ANTISPAM. Thx.
16×16サイズの紙を指定されたコマンドで半分ずつ折っていく問題(http://www.rubyquiz.com/quiz63.html)。最終的に1×1サイズになったところで、グリッドについていた番号を上から並べて出力する。
この例がわかりやすい。
12
34
fold("RB") => [3, 4, 2, 1]
fold("TL") => [3, 1, 2, 4]
コマンドは"T"(上辺を下辺に合わせるように折る。折った後、上辺側が上になる)、"B"(下辺を上辺に~)、"L"(左辺を右辺に~)、"R"(右辺を左辺に~)の4つ。折ったときに上になるほうは並びが反転するけど、下になるほうはそのままなことに注意する必要があるかな。
Extra credit: Make your fold function take an additional input parameter(s), the dimensions of the paper; dimensions should be power-of-2 in order to fold down to one cell.
サイズを指定できるようにするといいらしい。あと最終的に1つのマスにたたみこむために、1辺の長さを2の累乗にするべきとのこと。