挺搞笑的,收到一封猎头邮件,附送一道智力题,说是能解出就联系她……贴出来大家齐欢乐~
You must solve this puzzle to apply
There're 7 red tiles, 8 blue titles and one white title in a 4 x 4 plane. We could only move the white tile. When moving it, the white tile swaps the position with the adjacent tile. L, R, U, D are corresponding to four directions which the tile could be moved to (Left, Right, Up, Down) For example, starting from configuration (S), by the move sequence RDRDLwe reach the configuration (E). Now, starting from configuration (S), find the shortest way to reach configuration (T).
What is the move sequence of the path ?
p.s. 我真的不是来骗答案然后去面试的……
c742435
2014-01-24 18:35:52 +08:00
package {
import flash.display.Sprite;
import flash.text.TextField;
public class Untitled extends Sprite {
public function Untitled() {
var a:Array = new Array;
a[0xf00ff] = "";
var counter:int = 0;
work(0x00ff, 15, "");
trace(counter);
function work(v:uint, p:int, s:String):void
{
counter += 1;
if(0 == counter % 100)
{
trace(counter);
}
if(0x5858 == v)
{
trace("a[" + 0x5858 + "]=" + a[v]);
}
if(s.length > 600)
return;
if((p & 3) < 3)
{
test(1, "U");
}
if((p & 3) > 0)
{
test(-1, "D");
}
if(p < 12)
{
test(4, "L");
}
if(p > 3)
{
test(-4, "R");
}
function test(n:int, sadd:String):void
{
var tempV:uint = calc(n);
var tempS:String;
var index:int = tempV | ((p + n) << 16);
if(!a[index])
{
tempS = s + sadd;
a[index] = tempS;
work(tempV, p + n, tempS);
}
}
function calc(n:int):uint
{
var fromMask:int = 1 << p;//原有位置被置为目标位置的值
var toMask:int = 1 << (p + n);//目标位置被置为0(光标位置总是为0)
return v & (0xffff ^ toMask) & (0xffff ^ fromMask) | ( (v & toMask ) && fromMask);
}
}
}
}
}
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
https://www.v2ex.com/t/98224
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.