挺搞笑的,收到一封猎头邮件,附送一道智力题,说是能解出就联系她……贴出来大家齐欢乐~
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 20:49:36 +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 task:Vector.<VPS> = new Vector.<VPS>;
task.push(new VPS(0x00ff, 15, ""));
var counter:int = 0;
while(task.length)
{
work();
}
function work():void
{
if(!task.length)
{
return;
}
var vps:VPS = task.shift();
var v:uint = vps.v, p:int = vps.p, s:String = vps.s;
if(0x5a5a == v && 0 == p)
{
trace("a[" + ((p << 16) | v) + "]=" + s);
}
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;
task.push(new VPS(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);
}
}
}
}
}
class VPS
{
var v:uint;
var p:int;
var s:String;
function VPS(v:uint, p:int, s:String)
{
this.v = v;
this.p = p;
this.s = s;
}
}
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
https://www.v2ex.com/t/98224
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.