PowerShell中,299个 292字节
假定地图是矩形。
它x
改为使用·
。要获取·
,您需要将脚本另存为ASCII(不是UTF-8)并替换x
为·
。
filter f{$l=($_-split"
")[0].length
$p,$d,$e='x','\d',' '|%{"$_(?=E)|(?<=E)$_|$_(?=[\s\S]{$l}E)|(?<=E[\s\S]{$l})$_"}
for($r=1;$_-notmatch$p;$r++){$m=$_-replace'F','E'-replace'G','F'-replace'H','G'
if($m-match$d){$m=$m-replace$Matches[0],'H'}$m=$m-replace$e,'E'
if($m-eq$_){return -1}$_=$m}$r}
取消测试的脚本:
filter f{
#Write-Host "`nStep:`n$_" # uncomment this to display each step
$l = ($_ -split "`n")[0].length
$p,$d,$e = 'x', '\d', ' '| % {"$_(?=E)|(?<=E)$_|$_(?=[\s\S]{$l}E)|(?<=E[\s\S]{$l})$_"}
for($r = 1;$_ -notmatch $p;$r++) {
$m = $_ -replace 'F', 'E' -replace 'G', 'F' -replace 'H', 'G'
if ($m -match $d) {
$m = $m -replace $Matches[0], 'H'
}
$m = $m -replace $e, 'E'
if ($m -eq $_) {
return -1
}
$_=$m
}
$r
}
@(
, (2, @"
****
*x E
****
"@)
, (1, @"
****
* xE
****
"@)
, (1, @"
****
* x*
* E*
****
"@)
, (1, @"
****
* E*
* x*
****
"@)
, (-1, @"
****
2 E1
* *
****
"@)
, (28, @"
*****************
* 1
* CCCCCCCCCCCCC *
* ************* *
* CCCCCCCCCCCCC *
* *
**********E******
*****************
* 2
* CCCCCCCCCCCCC *
* ************* *
* xCCCCCCCCCCCC *
* 1
*****************
*****************
* 3
* xxxxCxxCCCCCC *
* ************* *
* xxxCCCCCCCCCC *
* 2
*****************
*****************
* *
* xxxxxxCxxxxxx *
* ************* *
* xxCxxxxxxxCxx *
* 3
*****************
"@)
, (16, @"
*****************
* 1
* CCCCCCCCCCCCC *
* ************* *
* CCCCCCCCCCCCC *
* *
**********E******
*****************
* *
* CCCCCCCCCCCCC *
* ************* *
* xCCCCCCCCCCCC *
* 3
*****************
*****************
* 3
* xxxxCxxCCCCCC *
* ************* *
* xxxCCCCCCCCCC *
* 2
*****************
*****************
* 2
* xxxxxxCxxxxxx *
* ************* *
* xxCxxxxxxxCxx *
* 1
*****************
"@)
, (29, @"
************
*CCCCCCCCC 1
* *
*CCCCCCCCC E
************
************
*CCCCCCCCC 2
* *
*CCCCCCCCC 1
************
************
*CCCCCCCCC 3
* *
*CCCCCCCCC 2
************
************
*xCCCCCCCC 4
* *
*xxCCCCCCC 3
************
************
*xxxxxxxxC *
* *
*xxxxxxxCC 4
************
"@
)
, (-1, @"
************
* *
* *
* E*
************
"@)
, (-1, @"
************
* xxxxx *
*x ****
* xxxxx * E
*********
"@)
) | % {
$e, $m = $_
$r = $m|f
"$($e-eq$r): $r $e"
}
输出:
True: 2 2
True: 1 1
True: 1 1
True: 1 1
True: -1 -1
True: 28 28
True: 16 16
True: 29 29
True: -1 -1
True: -1 -1
16个步骤的扩展输出,可用于停车:
Step:
*****************
* 1
* CCCCCCCCCCCCC *
* ************* *
* CCCCCCCCCCCCC *
* *
**********E******
*****************
* *
* CCCCCCCCCCCCC *
* ************* *
* xCCCCCCCCCCCC *
* 3
*****************
*****************
* 3
* xxxxCxxCCCCCC *
* ************* *
* xxxCCCCCCCCCC *
* 2
*****************
*****************
* 2
* xxxxxxCxxxxxx *
* ************* *
* xxCxxxxxxxCxx *
* 1
*****************
Step:
*****************
* 1
* CCCCCCCCCCCCC *
* ************* *
* CCCCCCCCCCCCC *
* E *
**********E******
*****************
* *
* CCCCCCCCCCCCC *
* ************* *
* xCCCCCCCCCCCC *
* 3
*****************
*****************
* 3
* xxxxCxxCCCCCC *
* ************* *
* xxxCCCCCCCCCC *
* 2
*****************
*****************
* 2
* xxxxxxCxxxxxx *
* ************* *
* xxCxxxxxxxCxx *
* 1
*****************
Step:
*****************
* 1
* CCCCCCCCCCCCC *
* ************* *
* CCCCCCCCCCCCC *
* EEE *
**********E******
*****************
* *
* CCCCCCCCCCCCC *
* ************* *
* xCCCCCCCCCCCC *
* 3
*****************
*****************
* 3
* xxxxCxxCCCCCC *
* ************* *
* xxxCCCCCCCCCC *
* 2
*****************
*****************
* 2
* xxxxxxCxxxxxx *
* ************* *
* xxCxxxxxxxCxx *
* 1
*****************
Step:
*****************
* 1
* CCCCCCCCCCCCC *
* ************* *
* CCCCCCCCCCCCC *
* EEEEE *
**********E******
*****************
* *
* CCCCCCCCCCCCC *
* ************* *
* xCCCCCCCCCCCC *
* 3
*****************
*****************
* 3
* xxxxCxxCCCCCC *
* ************* *
* xxxCCCCCCCCCC *
* 2
*****************
*****************
* 2
* xxxxxxCxxxxxx *
* ************* *
* xxCxxxxxxxCxx *
* 1
*****************
Step:
*****************
* 1
* CCCCCCCCCCCCC *
* ************* *
* CCCCCCCCCCCCC *
* EEEEEEE *
**********E******
*****************
* *
* CCCCCCCCCCCCC *
* ************* *
* xCCCCCCCCCCCC *
* 3
*****************
*****************
* 3
* xxxxCxxCCCCCC *
* ************* *
* xxxCCCCCCCCCC *
* 2
*****************
*****************
* 2
* xxxxxxCxxxxxx *
* ************* *
* xxCxxxxxxxCxx *
* 1
*****************
Step:
*****************
* 1
* CCCCCCCCCCCCC *
* ************* *
* CCCCCCCCCCCCC *
* EEEEEEEEE *
**********E******
*****************
* *
* CCCCCCCCCCCCC *
* ************* *
* xCCCCCCCCCCCC *
* 3
*****************
*****************
* 3
* xxxxCxxCCCCCC *
* ************* *
* xxxCCCCCCCCCC *
* 2
*****************
*****************
* 2
* xxxxxxCxxxxxx *
* ************* *
* xxCxxxxxxxCxx *
* 1
*****************
Step:
*****************
* 1
* CCCCCCCCCCCCC *
* ************* *
* CCCCCCCCCCCCC *
* EEEEEEEEEEE*
**********E******
*****************
* *
* CCCCCCCCCCCCC *
* ************* *
* xCCCCCCCCCCCC *
* 3
*****************
*****************
* 3
* xxxxCxxCCCCCC *
* ************* *
* xxxCCCCCCCCCC *
* 2
*****************
*****************
* 2
* xxxxxxCxxxxxx *
* ************* *
* xxCxxxxxxxCxx *
* 1
*****************
Step:
*****************
* 1
* CCCCCCCCCCCCC *
* ************* *
* CCCCCCCCCCCCCE*
* EEEEEEEEEEEE*
**********E******
*****************
* *
* CCCCCCCCCCCCC *
* ************* *
* xCCCCCCCCCCCC *
* 3
*****************
*****************
* 3
* xxxxCxxCCCCCC *
* ************* *
* xxxCCCCCCCCCC *
* 2
*****************
*****************
* 2
* xxxxxxCxxxxxx *
* ************* *
* xxCxxxxxxxCxx *
* 1
*****************
Step:
*****************
* 1
* CCCCCCCCCCCCC *
* *************E*
* CCCCCCCCCCCCCE*
* EEEEEEEEEEEEE*
**********E******
*****************
* *
* CCCCCCCCCCCCC *
* ************* *
* xCCCCCCCCCCCC *
* 3
*****************
*****************
* 3
* xxxxCxxCCCCCC *
* ************* *
* xxxCCCCCCCCCC *
* 2
*****************
*****************
* 2
* xxxxxxCxxxxxx *
* ************* *
* xxCxxxxxxxCxx *
* 1
*****************
Step:
*****************
* 1
* CCCCCCCCCCCCCE*
* *************E*
* CCCCCCCCCCCCCE*
* EEEEEEEEEEEEEE*
**********E******
*****************
* *
* CCCCCCCCCCCCC *
* ************* *
* xCCCCCCCCCCCC *
* 3
*****************
*****************
* 3
* xxxxCxxCCCCCC *
* ************* *
* xxxCCCCCCCCCC *
* 2
*****************
*****************
* 2
* xxxxxxCxxxxxx *
* ************* *
* xxCxxxxxxxCxx *
* 1
*****************
Step:
*****************
* E1
* CCCCCCCCCCCCCE*
* *************E*
* CCCCCCCCCCCCCE*
*EEEEEEEEEEEEEEE*
**********E******
*****************
* *
* CCCCCCCCCCCCC *
* ************* *
* xCCCCCCCCCCCC *
* 3
*****************
*****************
* 3
* xxxxCxxCCCCCC *
* ************* *
* xxxCCCCCCCCCC *
* 2
*****************
*****************
* 2
* xxxxxxCxxxxxx *
* ************* *
* xxCxxxxxxxCxx *
* 1
*****************
Step:
*****************
* EEH
* CCCCCCCCCCCCCE*
* *************E*
*ECCCCCCCCCCCCCE*
*EEEEEEEEEEEEEEE*
**********E******
*****************
* *
* CCCCCCCCCCCCC *
* ************* *
* xCCCCCCCCCCCC *
* 3
*****************
*****************
* 3
* xxxxCxxCCCCCC *
* ************* *
* xxxCCCCCCCCCC *
* 2
*****************
*****************
* 2
* xxxxxxCxxxxxx *
* ************* *
* xxCxxxxxxxCxx *
* H
*****************
Step:
*****************
* EEEG
* CCCCCCCCCCCCCE*
*E*************E*
*ECCCCCCCCCCCCCE*
*EEEEEEEEEEEEEEE*
**********E******
*****************
* *
* CCCCCCCCCCCCC *
* ************* *
* xCCCCCCCCCCCC *
* 3
*****************
*****************
* 3
* xxxxCxxCCCCCC *
* ************* *
* xxxCCCCCCCCCC *
* 2
*****************
*****************
* 2
* xxxxxxCxxxxxx *
* ************* *
* xxCxxxxxxxCxx *
* G
*****************
Step:
*****************
* EEEEF
*ECCCCCCCCCCCCCE*
*E*************E*
*ECCCCCCCCCCCCCE*
*EEEEEEEEEEEEEEE*
**********E******
*****************
* *
* CCCCCCCCCCCCC *
* ************* *
* xCCCCCCCCCCCC *
* 3
*****************
*****************
* 3
* xxxxCxxCCCCCC *
* ************* *
* xxxCCCCCCCCCC *
* 2
*****************
*****************
* 2
* xxxxxxCxxxxxx *
* ************* *
* xxCxxxxxxxCxx *
* F
*****************
Step:
*****************
*E EEEEEE
*ECCCCCCCCCCCCCE*
*E*************E*
*ECCCCCCCCCCCCCE*
*EEEEEEEEEEEEEEE*
**********E******
*****************
* *
* CCCCCCCCCCCCC *
* ************* *
* xCCCCCCCCCCCC *
* 3
*****************
*****************
* 3
* xxxxCxxCCCCCC *
* ************* *
* xxxCCCCCCCCCC *
* 2
*****************
*****************
* 2
* xxxxxxCxxxxxx *
* ************* *
* xxCxxxxxxxCxx *
* EE
*****************
Step:
*****************
*EE EEEEEEE
*ECCCCCCCCCCCCCE*
*E*************E*
*ECCCCCCCCCCCCCE*
*EEEEEEEEEEEEEEE*
**********E******
*****************
* *
* CCCCCCCCCCCCC *
* ************* *
* xCCCCCCCCCCCC *
* 3
*****************
*****************
* 3
* xxxxCxxCCCCCC *
* ************* *
* xxxCCCCCCCCCC *
* 2
*****************
*****************
* 2
* xxxxxxCxxxxxx *
* ************* *
* xxCxxxxxxxCxxE*
* EEE
*****************
True: 16 16
说明
这是一种Lee寻路算法。只有一件聪明的事:斜坡上的3步被实现为虚拟状态H->G->F->E
一位天才停车场设计师的Powershell,377 369字节
停车设计是一种2D string array
。没有关于地图的假设:任何长度的字符串,没有墙壁的地板,没有入口的停车位,多层和多重出口的坡道。类的成本是+ 26%。
filter f{for($r=1;$_-notmatch$p;$r++){$m=$_-replace'F','E'-replace'G','F'-replace'H','G'
if($m-match$d){$m=$m-replace$Matches[0],'H'}$m=$m-replace$e,'E'
if($m-eq$_){return-1}$_=$m}$r}$g={$l=($args|%{$_|%{$_.length}}|sort)[-1]
$p,$d,$e='x','\d',' '|%{"$_(?=E)|(?<=E)$_|$_(?=[\s\S]{$l}E)|(?<=E[\s\S]{$l})$_"}
(($args|%{$_.PadRight($l,'*')-join"
"})-join"
"+'-'*$l+"
")|f}
取消测试的脚本:
filter f{
#Write-Host "`nStep:`n$_" # uncomment this to display each step
for($r = 1;$_ -notmatch $p;$r++) {
$m = $_ -replace 'F', 'E' -replace 'G', 'F' -replace 'H', 'G'
if ($m -match $d) {
$m = $m -replace $Matches[0], 'H'
}
$m = $m -replace $e, 'E'
if ($m -eq $_) {
return -1
}
$_=$m
}
$r
}
$g = {
$l = ($args| % {$_| % {$_.length}}|sort)[-1]
$p,$d,$e = 'x', '\d', ' '| % {"$_(?=E)|(?<=E)$_|$_(?=[\s\S]{$l}E)|(?<=E[\s\S]{$l})$_"}
(($args| % {$_.PadRight($l, '*') -join "`n"}) -join "`n"+'-' * $l+"`n")|f
}
@(
, (2, @(, (
"****",
"*x E",
"****"
)))
, (1, @(, (
"****",
"* xE",
"****"
)))
, (1, @(, (
"****",
"* x*",
"* E*",
"****"
)))
, (1, @(, (
"****",
"* E*",
"* x*",
"****"
)))
, (-1, @(, (
"****",
"2 E1",
"* *",
"****"
)))
, (28, @(, (
"*****************",
"* 1",
"* CCCCCCCCCCCCC *",
"* ************* *",
"* CCCCCCCCCCCCC *",
"* *",
"**********E******"
), (
"*****************",
"* 2",
"* CCCCCCCCCCCCC *",
"* ************* *",
"* xCCCCCCCCCCCC *",
"* 1",
"*****************"
), @(
"*****************",
"* 3",
"* xxxxCxxCCCCCC *",
"* ************* *",
"* xxxCCCCCCCCCC *",
"* 2",
"*****************"
), @(
"*****************",
"* *",
"* xxxxxxCxxxxxx *",
"* ************* *",
"* xxCxxxxxxxCxx *",
"* 3",
"*****************"
)))
, (16, @(, (
"*****************",
"* 1",
"* CCCCCCCCCCCCC *",
"* ************* *",
"* CCCCCCCCCCCCC *",
"* *",
"**********E******"
), @(
"*****************",
"* *",
"* CCCCCCCCCCCCC *",
"* ************* *",
"* xCCCCCCCCCCCC *",
"* 3",
"*****************"
), @(
"*****************",
"* 3",
"* xxxxCxxCCCCCC *",
"* ************* *",
"* xxxCCCCCCCCCC *",
"* 2",
"*****************"
), @(
"*****************",
"* 2",
"* xxxxxxCxxxxxx *",
"* ************* *",
"* xxCxxxxxxxCxx *",
"* 1",
"*****************"
)))
, (29, @(, (
"************",
"*CCCCCCCCC 1",
"* *",
"*CCCCCCCCC E",
"************"
), @(
"************",
"*CCCCCCCCC 2",
"* *",
"*CCCCCCCCC 1",
"************"
), @(
"************",
"*CCCCCCCCC 3",
"* *",
"*CCCCCCCCC 2",
"************"
), @(
"************",
"*xCCCCCCCC 4",
"* *",
"*xxCCCCCCC 3",
"************"
), @(
"************",
"*xxxxxxxxC *",
"* *",
"*xxxxxxxCC 4",
"************"
)))
, (-1, @(, (
"************",
"* *",
"* *",
"* E*",
"************"
)))
, (-1, @(, (
"************",
"* xxxxx *",
"*x ****",
"* xxxxx * E",
"*********"
)))
) | % {
$e, $m = $_
$r = &$g @m
"$($e-eq$r): $r $e"
}