flash on 2010-1-14
@see http://okajima.air-nifty.com/b/2010/01/post-abc6.html
22ふんでした
/**
* Copyright uwi ( http://wonderfl.net/user/uwi )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/d0TA
*/
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
// @see http://okajima.air-nifty.com/b/2010/01/post-abc6.html
// 22ふんでした
public class FlashTest extends Sprite {
public function FlashTest() {
var tf : TextField = new TextField();
addChild(tf);
tf.defaultTextFormat = new TextFormat("Courier New");
tf.width = 300;
tf.height = 300;
tf.text = solve();
}
private function solve() : String {
var s : uint = MAZE.indexOf("S");
var g : uint = MAZE.indexOf("G");
var l : uint = "**************************\n".length;
var mem : Object = {};
mem[s] = [];
var newer : Array = [s];
while(newer.length > 0){
var nextNewer : Array = [];
for each(var o : uint in newer){
for each(var d : int in [-l, l, 1, -1]){
var p : uint = o + d;
if(MAZE.charAt(p) == "G"){
var str : String = MAZE;
for each(var e : uint in mem[o]){
str = str.substring(0, e) + "$" + str.substring(e + 1);
}
return str;
}
if(MAZE.charAt(p) == " " && (mem[p] == null || mem[p].length - mem[o].length >= 1)){
mem[p] = mem[o].concat();
mem[p].push(p);
nextNewer.push(p);
}
}
}
newer = nextNewer;
}
return null;
}
private const MAZE : String =
"**************************\n" +
"*S* * *\n" +
"* * * * ************* *\n" +
"* * * ************ *\n" +
"* * *\n" +
"************** ***********\n" +
"* *\n" +
"** ***********************\n" +
"* * G *\n" +
"* * *********** * *\n" +
"* * ******* * *\n" +
"* * *\n" +
"**************************";
}
}