aligo
2010-07-29 23:18:37 +08:00
4个人排成一圈,或在排成1字一排貌似最后都没法传到a手里呢
[code]
var count = 0;
var routes = [];
var limit = 5;
var circle = false;
var found = function (route)
{
routes.push(route);
//alert(route);
}
var pass = function (cur, time, route)
{
if ((cur === 1) && (time === limit)) {
count++;
found(route);
}
if (circle && (cur > 4)) {
cur = 1;
}
if (circle && (cur < 1)) {
cur = 4;
}
if ((cur < 5) && (cur > 0) && (time < limit) ) {
pass(cur + 1, time + 1, route + '>');
pass(cur - 1, time + 1, route + '<');
}
}
pass(1, 0, '');
alert(count + ':' + routes);
[/code]