Powershell, 299 292 바이트
지도가 직사각형 인 것으로 가정합니다 .
x
대신 사용 합니다 ·
. 를 얻으려면 ·
스크립트를 UTF-8이 아닌 ASCII로 ASCII로 저장하고에 바꾸어야 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}
Ungolfed 및 테스트 스크립트 :
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}
Ungolfed 및 테스트 스크립트 :
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"
}