桥梁和隧道


32

您负责建立新的高速公路。但是,它穿过山区,因此需要许多桥梁和隧道。高速公路本身应保持在单一水平。

输入值

您将获得有关标准输入中的山脉外观的ASCII粗略描述,例如:

                         /\                                
                        /  \                               
                   /\  /    \                              
            /\    /  \/      \                             
           /  \  /            \                  /\        
          /    \/              \                /  \       
_        /                      \        /\    /    \      
 \      /                        \      /  \  /      \  /\ 
  \    /                          \    /    \/        \/  \
   \  /                            \  /                    
    \/                              \/                     

_第一列标志开始和道路的水平。山脉是连续的,如果最后一段是桥梁,则它具有偶数个字符。

您可能会假设输入行永远不会超过100个字符,并且输入行不会超过15个。每行的长度相同,可能会在末尾加空格。这条路永远不会在山上或桥梁中开始。输入中道路砖之后的第一件事是向下或向上倾斜。

输出量

输出是相同的山脉,除了现在有一条以前只是起点的道路。输出在标准输出上给出。

为此,有许多规则:

  1. 道路必须从输入中指示的位置开始,并始终保持相同的水平。为了简化操作,我们准备了许多预制的路砖,如下所示_

    _______
     \    /
      \/\/
    
  2. 道路必须延伸到山脉的远端(即输入线的长度决定了道路的走远)。

  3. 每当要走山路时,都必须钻隧道。隧道直接穿过山峰,并在起点和终点留有孔(即,隧道以在起点处的闭合括号和在终点处的开口括号代替山坡)。

  4. 隧道在山上通常有顶棚的隧道中离开。幸运的是,我们的预制路砖可用于加固天花板,以免隧道塌陷(必须使用隧道上方的线_来加固隧道):

          /\
         /  \
        /____\
    ___)______(__
     \/        \/
    
  5. 当山顶的高度不够时,无需加固隧道。对我来说,这听起来也很奇怪,但是有人告诉我,即使在这种情况下,预制的路砖也足够坚固,即使在间隔开的情况下也可以保持(当隧道正上方有斜坡时,不会绘制隧道顶棚):

           /\
        /\/__\
    ___)______(__
     \/        \/
    
  6. 每当道路需要穿越峡谷时,都需要桥梁。对于短桥,预制的路砖足够坚固,但在桥的开始和末端仍需要一点支撑(桥下的第一个下坡和上一个的上坡被替换Y为桥的支撑梁) ):

    _____
     Y  Y
      \/
    
  7. 较长的网桥需要其他支持。长长的桥是连续超过六个不受支撑的路砖的桥。长桥的中心需要一根支柱。可以使用我们的预制柱梁轻松构建柱,如下所示:|。每个支柱都需要其中两个,它们向下延伸到深渊的底部:

    _____________________________
     Y            ||            Y
      \        /\ || /\      /\/ 
       \  /\  /  \||/  \  /\/    
        \/  \/    \/    \/       
    
  8. 由于输入仅代表高速公路需要修建的整个山脉的一部分,因此它可能会突然终止于桥梁或隧道的中间。长连接规则仍然适用于最后一段,您可以假定超出给定输入的第一部分再次支持连接。

遵循以上规则,我们将获得以下输入信息:

                         /\                                
                        /  \                               
                   /\  /    \                              
            /\    /  \/      \                             
           /  \  /            \                  /\        
          /____\/______________\                /__\       
_________)______________________(________)(____)____(______
 Y      Y                        Y      Y  Y  Y      Y  YY 
  \    /                          \    /    \/        \/  \
   \  /                            \  /                    
    \/                              \/                     

按字符计数最短的代码获胜。行中的尾随空格将被忽略以进行验证。

样品输入1

_                                                           
 \                            /\                            
  \                          /  \                           
   \                        /    \                          
    \                /\    /      \              /\        /
     \    /\        /  \  /        \      /\  /\/  \      / 
      \  /  \      /    \/          \    /  \/      \/\  /  
       \/    \    /                  \  /              \/   
              \  /                    \/                    
               \/                                           

样品输出1

____________________________________________________________
 Y             ||             YY             ||             
  \            ||            /  \            ||             
   \           ||           /    \           ||             
    \          ||    /\    /      \          ||  /\        /
     \    /\   ||   /  \  /        \      /\ |/\/  \      / 
      \  /  \  ||  /    \/          \    /  \/      \/\  /  
       \/    \ || /                  \  /              \/   
              \||/                    \/                    
               \/                                           

样品输入2

                                           /\  /\                      
                                          /  \/  \                    /
           /\                            /        \  /\              / 
    /\    /  \                          /          \/  \            /  
   /  \  /    \/\                      /                \    /\    /   
  /    \/        \                    /                  \  /  \  /    
_/                \                  /                    \/    \/     
                   \                /                                  
                    \            /\/                                   
                     \  /\      /                                      
                      \/  \    /                                       
                           \  /                                        
                            \/                                         

样品输出2

                                           /\  /\                      
                                          /  \/  \                    /
           /\                            /        \  /\              / 
    /\    /  \                          /          \/  \            /  
   /  \  /    \/\                      /                \    /\    /   
  /____\/________\                    /__________________\  /__\  /____
_)________________(__________________)____________________()____()_____
                   Y       ||       Y                                  
                    \      ||    /\/                                   
                     \  /\ ||   /                                      
                      \/  \||  /                                       
                           \| /                                        
                            \/                                         

注意

为了与参考解决方案进行比较,忽略了输出中的尾随空格。

获奖条件

最短的代码胜出,这是高尔夫界的惯例。如果出现平局,则以较早的解决方案为准。

测试用例

有两个测试脚本,包含相同的测试用例:

在两种情况下都调用:<test script> <my program> [arguments]例如./test ruby bridges.rb./test.ps1 ./bridges.exe

另一个注意

该任务是2011-W24期间在我的大学举行的高尔夫比赛的一部分。参赛者的成绩和语言如下:

  • 304 – Perl
  • 343 – C
  • 375 – C
  • 648 – Python

我们自己的解决方案(感谢Ventero)是

  • 262 –红宝石

1
注意:我更新了测试脚本,其中一些测试用例的顶部包含一个意外的空行。现在应该修复。
乔伊,

Answers:


8

Perl中,210 195 194 193个字符

更新

相同的想法,但在很大程度上却有很大不同。

运行perl -p0(4个字符计入开关)。

($o,$c,$r,$b)=/((.+\n)?(_.+\n)(.+\n)?)/;/\n/;$n=$-[0];$c=~s{/ }{/_}g;$r=~y{ /\\}{_)(};map{s{\\(   +)  \1(/|\n)}{\\$1||$1$2}g,y{\\/}{Y}}$b;s/\Q$o/$c$r$b/;1while(s/_ /__/||s/(\|.{$n}) /$1|/s) 

这还需要更改bash测试脚本,以免过度引用args:

-   got=$("$cmd" "$args")
+   got=$("$cmd" $args)

顺便说一句,我非常感谢测试脚本@Joey。

评论:

#-p : implicitly read input and print after transformations
#-0 : "slurp mode": don't break lines

# grab the roadway line, along with the lines above and below for ceiling and buttresses
# also grab the whole match in $o for replacing later
($o,$c,$r,$b)=/((.+\n)?(_.+\n)(.+\n)?)/;

# compute line length
/\n/;$n=$-[0];

# start ceilings
$c=~s{/ }{/_}g;

# build the road and tunnels
$r=~y{ /\\}{_)(};

# use map to avoid repeating $b =~
map{
  # insert the pillar tops
  s{\\(   +)  \1(/|\n)}{\\$1||$1$2}g,
  # and the buttresses
  y{\\/}{Y}
} $b;

# put those 3 (or 2) lines back into the original
s/\Q$o/$c$r$b/;

# extend ceiling tiles to the right and pillars downward
1while(s/_ /__/||s/(\|.{$n}) /$1|/s)

编辑

  • 取代“{3,}用3个文字空间 ”,然后将+量词,以保存另一个字符
  • 使用1while(...)表格,我可以在脚本末尾省略分号

原始(查看历史记录以获取评论版本)

@a=map{($r=$n),y{ /\\}{_)(}if/_/;$n++;$_}<>;if($r){while($a[$r-1]=~s{(/[ _]*) }{$1_}){}}map{s{(^|\\)( {3,})  \2(/|$)}{$1$2||$2$3}g;y{\\/}{YY}}$a[$r+1];$_=join'',@a;/\n/;$n=$-[0];while(s/(\|.{$n}) /$1|/s){}print

直到我的工作开始,我才刻意使用@Howard的Perl解决方案,但是通过后来的研究,我可以提高自己的高尔夫水平。

特别是,用于隧道天花板和延伸支柱的正则表达式有所帮助。做得好,霍华德。

相反,我选择获取行长,使用隐式$ _进行打印,保留最后的分号并删除换行符的替代方法可能会将Howard缩短为222个字符。


1
对于bash测试脚本,感谢Ventero。我只是拿走了他创造的东西,然后猛砸它,直到它起作用为止;-)
Joey

6

Perl,234个字符

$_=join'',<>;$l=index($_,"\n");
($w)=/(_[^\n]*)/;$w=~y/ \\\//_()/;s/_[^\n]*/$w/e;
while(s/(\/[ _]*) (?=[^\n]*\n_)/$1_/||s/(_.{$l})[\\\/]/$1Y/s){}while(s/(\n( |Y *Y)*)Y( {3,})  \3(Y| ?\n)/\1Y\3||\3\4/||s/(?<=\|.{$l}) /|/s){}
print $_;

这是仅Perl正则表达式的解决方案。它通过了所有给定的测试用例。

相同但更易读的版本显示了获取结果所采取的步骤:

$_=join'',<>;                    # read the input
$l=index($_,"\n");               # determine length of line

($w)=/(_[^\n]*)/;                # extract the line starting with _
$w=~y/ \\\//_()/;                # and build road there (i.e. replace all chars in line)
s/_[^\n]*/$w/e;                  # put road back into string

while(s/(\/[ _]*) (?=[^\n]*\n_)/$1_/||s/(_.{$l})[\\\/]/$1Y/s){}
                                 # build ceiling of tunnels
                                 # build Y supports directly below the road

while(s/(\n( |Y *Y)*)Y( {3,})  \3(Y| ?\n)/\1Y\3||\3\4/||s/(?<=\|.{$l}) /|/s){}
                                 # build center support in middle of bridges
                                 # and extend them down to the ground

print $_;                        # print result

1
kes 在所有地方看起来都很邪恶;-)。为什么Perl人们总是必须使用正则表达式解决所有问题?:-þ–
Joey

由于regices是一个真正的Perl黑客武器:d
FUZxxl

2
一个perl黑客(我过去几年都这样称呼我自己)想到了另一种方式,乔伊:如果用正则表达式可以解决问题,为什么还要打扰其他人呢?我认为,对于正则表达式而言,这确实是一个理想的问题:这就是您自己或实现回溯状态机。
2011年

那并不意味着完全严肃。我自己的参考解决方案最初也使用了许多正则表达式。
乔伊,

4

C ++,662 622 598个字符,4行

#include<iostream>
#include<string>
#define s for(
#define v g[t][f]
int t,f,r,q,m=-1,w,b,e,h,j,x,y,l,c=18;int main(){std::string g[19];s;r<19;h=c)getline(std::cin,g[r++]);s;c>=0;g[c--].push_back(0))(q=g[c].size())&&g[c][0]-95?0:r=c;s;c<q;y=0){x=g[r][++c];x==47?x=41,w=e=1:++y;x==92?x=40,w=0:++y;t=r-1;f=c;y>1?x=95,w?r&&v==32?v=95:0:++b:0;c-q?0:e=1;t++;s v=x;m<0;)g[h].find(47)<g[h--].npos?m=h:0;t=r+1;if(r<m){(y=v)==47?y=89,e=1:0;v=y-92?y:89;if(e){y=e=0;if((b/=2)>4){j=l=r+1;s;!y;t=j,f=c-b+1,v==32?v=124,++j:0)t=l,y=f=c-b,v==32?v=124,l++,y=0:0;}b=0;}}}s f=q,t=0;t<=m;std::cout<<g[t++]<<'\n')v=32;}

应该是这样,我已经使用powershell脚本对此进行了测试,所以应该没问题...

编辑1

用数字替换所有char常量,删除对std :: cout的连续调用以及其他一些小的更改。

编辑2

最后一次编辑,只是使它小于600。把g [t] [f]当作#define并进行了一些修改。


是的,我有一些错误的测试案例,但这是我自己的错。现在看起来不错:-)
Joey

有帮助#define std::吗?
FUZxxl

@FUZxxl,我不这么认为,我只使用4次“ std ::”,所以这是20个字符,如果我使用define,则在每个这些地方我都需要2个字符(例如,使用as std的“ cout” ::),并且定义将超过12个字符,“使用命名空间std”也不值得。
斯科特·洛根

3

红宝石, 382个 356 353字符

我想尝试一下非正则表达式的解决方案。

m=$<.read;n,r,s,$e,t=(/\n/=~m)+1,/^_/=~m,m.size,(u,d=47,92),0;def j y;$e.member? y;end;(n-1).times{|i|x=r+i;c=m[x];j(c)||(m[x]=95;a,b=x-n,x+n;t<41||a<0||m[a]>32||m[a]=95;b>s||!j(m[b])||(m[b]<d||(p=(/\/|\n/=~m[b..s])/2+b;p-b<4||(w=[f=false,f];p.step(s,n){|p|2.times{|i|(w[i]||=j m[i=p+i])||m[i]='|'}}));m[b]='Y'));c!=u||t=m[x]=41;c!=d||t=m[x]=40};print m

这里最大的空间节省方法是使用条件||运算符代替if - elsif - end。因此,if(a) lorem_ipsum end我没有写东西!a||lopem_ipsum。使用括号可以包含更大的块!a||(block)。如果条件包括&&运算符,则必须通过使用括号和!或使用De Morgan定律来。

话多了也一样

# read the STDIN to string
mountains = $<.read
line_length,road_level,size,$slopes,in_tunnel =
        (/\n/ =~ mountains) + 1, # Fint the first new line
        /^_/ =~ mountains, # Find the index of the road
        mountains.size, 
        (slope_up,slope_down=47,92),
        0

def is_slope y;$slopes.member? y;end

# For each index in the road line
(line_length - 1).times { |i|
  curindex = road_level + i
  curchar = mountains[curindex]

  # If not a slope then
  (is_slope(curchar))|| (

    # mark road as underscore
    mountains[curindex] = 95
    above, below = curindex - line_length, curindex + line_length

    # add roof to tunnel if in tunnel and the mountain
    # is high enough
    in_tunnel<41||above<0||mountains[above]>32||mountains[above]=95

    # If there's a slope character below the road
    below>size||!is_slope(mountains[below])||(

      # if there's a downward slop - start a bridge
      mountains[below]<slope_down||(

          # If bridge is longer than 6 characters
          # Add support to the middle
          support_pos = (/\/|\n/=~mountains[below..size])/2+below
          support_pos-below<4||(
            # Init collision detection
            collision_detected=[f=false,f]
            # Build supports as long as 
            # There is mountains below
            support_pos.step(size,line_length) { |support_pos|

               # Add two parallel suppports
               2.times { |i|

               # Add support if the bottom of the 
               # gap has not been reached
               (collision_detected[i]||=is_slope(mountains[i=support_pos+i]))||mountains[i] = '|'
               }
            }
          )
      )

      # Add support to the beginning and to the end
      # of the bridge
      mountains[below] = 'Y'
    )
  )

  # Add tunnel entrance and exit
  curchar!=slope_up||in_tunnel=mountains[curindex]=41
  curchar!=slope_down||in_tunnel=mountains[curindex]=40
}

print mountains

测试还可以-我刚刚在粘贴测试脚本时搞砸了……很尴尬。
Aleksi Yrttiaho 2011年

2

Scala,462个字符

object B extends App{var r="""(?s)((?:.*\n)?)((?:.*?\n)?)(_.*?\n)(.*?\n)(.*)""".r
var r(a,b,c,d,e)=io.Source.stdin.mkString
var s=a+b.replaceAll("(?<=/ {0,99}) (?=.*\\\\)","_")+c.replaceAll("\\\\","(").replaceAll("/",")").replaceAll(" ","_")+d.replaceAll("\\\\( {3,99})  \\1/","Y$1||$1Y").replaceAll("\\\\( {3,99})  \\1\\n","Y$1||$1\n").replaceAll("\\\\( {0,9})/","Y$1Y")+e
for(i<-1 to 15)s=s.replaceAll("(?s)(?<=\\|.{"+s.split("\n")(0).size+"}) ","|")
print(s)}

并不是特别有竞争力,但是今天我已经学到了很多有关正则表达式的知识。:-)


2

Erlang,1182个字符

-module(b).
-export([t/0]).
t()->r([]).
r(R)->case io:get_line("")of eof->{_,Q}=lists:foldl(fun([$ |L],{$_,Q})->{$ ,[[$X|L]|Q]};([C|_]=L,{_,Q})->{C,[L|Q]}end,{$ ,[]},R),{_,P}=lists:foldl(fun s/2,{s,[]},lists:flatten(Q)),io:put_chars(lists:reverse(P));L->r([L|R])end.
s($X,{s,R})->{{r,s},[$ |R]};s($/,{{r,s},R})->{{r,r},[$/|R]};s($\\,{{r,r},R})->{{r,s},[$\\|R]};s($\n,{{r,_},R})->{u,[$\n|R]};s(_,{{r,r}=S,R})->{S,[$_|R]};s($_,{_,R})->{u,[$_|R]};s($\n,{u,R})->{{g,i,1,1,[]},[$\n|R]};s($\\,{u=S,R})->{S,[$(|R]};s($/,{u=S,R})->{S,[$)|R]};s(_,{u=S,R})->{S,[$_|R]};s($\\,{{g,i,X,_L,T},R})->{{g,o,X+1,X,[$Y|T]},R};s($/,{{g,o,X,L,T},R})->a(o,X,L),{{g,i,X+1,X,[$Y|T]},R};s($\n,{{g,S,X,L,T},R})->a(S,X,L),{{d,1},[$\n,f(T,X)|R]};s(C,{{g,S,X,L,T},R})->{{g,S,X+1,L,[C|T]},R};s($\n,{{d,_},R})->{{d,1},[$\n|R]};s($ ,{{d,X},R})->{{d,X+1},[case get(X)of y->$|;_->$ end|R]};s($/,{{d,X},R})->put(X,n),{{d,X+1},[$/|R]};s($\\,{{d,X},R})->put(X,n),{{d,X+1},[$\\|R]};s($\n=N,{S,R})->{S,[N|R]};s(X,{S,R})->{S,[X|R]}.
a(o,X,L)when X-L-1>6->Pos=round((X-L-1)/2+L),put(Pos,y),put(Pos+1,y);a(_,_,_)->v.
f(L,M)->{_,R}=lists:foldl(fun(C,{X,R})->case get(M-X)of y->{X+1,[$||R]};_->{X+1,[C|R]}end end,{1,[]},L),R.

完全没有竞争力。老实说,我只是对制作一些漂亮的ASCII艺术感兴趣,而不是在打高尔夫球。请注意,这不使用正则表达式,而是由我自己编写状态机。这也将需要shell脚本中的过度引用修复,如上面的perl解决方案中所述。


1

电源外壳, 300个 295 287字节

从DCharness的答案中偷窥了-8个字节。

param($s)filter e{$r,$e=$_-split'#';$e|%{$r=$r-replace($_-split';')};$r}
$x=$s-match'(.+
)?(_.+)(
.+)?'
$o,$c,$r,$b=$Matches[0..3]
for($s=$s|% *ce $o(("$c#/ ;/_"|e)+("$r# ;_#/;)#\\;("|e)+($b+'#\\(   +)  \1;\$1||$1#/|\\;Y'|e));$s-ne($x="$s#_ ;__#(?s)(?<=\|.{$($r|% Le*)}) ;|"|e)){$s=$x}$s

取消测试的脚本:

$f = {

param($s)
$x=$s-match'(.+
)?(_.+)(
.+)?'
$o,$c,$r,$b=$Matches[0..3]
$c=$c-replace'/ ','/_'                  # we assume that road does not start as a tunnel
$r=$r-replace' ','_'
$r=$r-replace'/',')'
$r=$r-replace'\\','('
$b=$b-replace'\\(   +)  \1','\$1||$1'   # we assume that road does not start as a bridge under a chasm
$b=$b-replace'/|\\','Y'
$s=$s.replace($o,"$c$r$b")              # string method replace (not operator) does not handle regexp
for(;$s-ne($x=$s-replace'_ ','__'-replace"(?s)(?<=\|.{$($r.Length)}) ",'|')){$s=$x}
$s

}

$pass = 0
$count = 0

@(
# Test 2
,(2,@'
    /\                  /\                  /\        
   /  \                /  \                /  \       
  /____\              /____\              /____\      
_)______(____________)______(____________)______(_____
         Y    ||    Y        Y    ||    Y        Y    
          \   ||   /          \   ||   /          \   
           \  ||  /            \  ||  /            \  
            \ || /              \ || /              \ 
             \||/                \||/                \
              \/                  \/                  
'@,@'
    /\                  /\                  /\        
   /  \                /  \                /  \       
  /    \              /    \              /    \      
_/      \            /      \            /      \     
         \          /        \          /        \    
          \        /          \        /          \   
           \      /            \      /            \  
            \    /              \    /              \ 
             \  /                \  /                \
              \/                  \/                  
'@)

# Test 1
,(1,@'
____________________________________________________________
 Y             ||             YY             ||             
  \            ||            /  \            ||             
   \           ||           /    \           ||             
    \          ||    /\    /      \          ||  /\        /
     \    /\   ||   /  \  /        \      /\ |/\/  \      / 
      \  /  \  ||  /    \/          \    /  \/      \/\  /  
       \/    \ || /                  \  /              \/   
              \||/                    \/                    
               \/                                           
'@,@'
_                                                           
 \                            /\                            
  \                          /  \                           
   \                        /    \                          
    \                /\    /      \              /\        /
     \    /\        /  \  /        \      /\  /\/  \      / 
      \  /  \      /    \/          \    /  \/      \/\  /  
       \/    \    /                  \  /              \/   
              \  /                    \/                    
               \/                                           
'@)

# Test 3
,(3,@'
    /\                 
   /  \                
  /____\/\/\/\/\/\/\/\ 
_)____________________(
'@,@'
    /\                 
   /  \                
  /    \/\/\/\/\/\/\/\ 
_/                    \
'@)

# Test 4
,(4,@'
___________________________________________________
 Y           ||           YY          ||          Y
  \          ||          /  \         |/\        / 
   \         ||         /    \        /  \      /  
    \    /\  ||    /\  /      \      /    \    /   
     \  /  \ ||   /  \/        \    /      \  /    
      \/    \||  /              \  /        \/     
             \| /                \/                
              \/                                   
'@,@'
_                                                  
 \                        /\                      /
  \                      /  \          /\        / 
   \                    /    \        /  \      /  
    \    /\        /\  /      \      /    \    /   
     \  /  \      /  \/        \    /      \  /    
      \/    \    /              \  /        \/     
             \  /                \/                
              \/                                   
'@)

# Test 5
,(5,@'
                                                      /
                                                     / 
                                                    /__
___________________________________________________)___
 Y           ||           YY          ||          Y    
  \          ||          /  \         |/\        /     
   \         ||         /    \        /  \      /      
    \    /\  ||    /\  /      \      /    \    /       
     \  /  \ ||   /  \/        \    /      \  /        
      \/    \||  /              \  /        \/         
             \| /                \/                    
              \/                                       
'@,@'
                                                      /
                                                     / 
                                                    /  
_                                                  /   
 \                        /\                      /    
  \                      /  \          /\        /     
   \                    /    \        /  \      /      
    \    /\        /\  /      \      /    \    /       
     \  /  \      /  \/        \    /      \  /        
      \/    \    /              \  /        \/         
             \  /                \/                    
              \/                                       
'@)

# Test 6
,(6,@'
_______________________________)
 YYYYYYYYYYYYYYYYYYYYYYYYYYYYYY 
'@,@'
_                              /
 \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ 
'@)

# Test 7
,(7,@'
_________________________________)
 Y              ||              Y 
  \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/  
'@,@'
_                                /
 \                              / 
  \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/  
'@)

# Test 8
,(8,@'
      /\    /\    /\    /\    /\    /\ 
_)(__)__(__)__(__)__(__)__(__)__(__)__(
   YY    YY    YY    YY    YY    YY    
'@,@'
      /\    /\    /\    /\    /\    /\ 
_/\  /  \  /  \  /  \  /  \  /  \  /  \
   \/    \/    \/    \/    \/    \/    
'@)

# Test 9
,(9,@'
  /\/\/\/\/\/\/\/\ 
_)________________(
'@,@'
  /\/\/\/\/\/\/\/\ 
_/                \
'@)

# Test 10
,(10,@'
      /\                                                            /\                              
     /  \                                                          /  \                             
    /    \                                                        /    \                            
   /      \                                                      /      \                           
  /________\                                                    /________\/\/\/\/\                  
_)__________(__________________________________________________)__________________(______)(_________
             Y                       ||                       Y                    Y    Y  Y   ||   
              \                      ||    /\                /                      \  /    \  ||  /
               \    /\               ||   /  \              /                        \/      \ || / 
                \  /  \              ||  /    \            /                                  \||/  
                 \/    \             || /      \          /                                    \/   
                        \        /\  ||/        \        /                                          
                         \      /  \ |/          \      /                                           
                          \    /    \/            \    /                                            
                           \/\/                    \/\/                                             
'@,@'
      /\                                                            /\                              
     /  \                                                          /  \                             
    /    \                                                        /    \                            
   /      \                                                      /      \                           
  /        \                                                    /        \/\/\/\/\                  
_/          \                                                  /                  \      /\         
             \                                                /                    \    /  \        
              \                            /\                /                      \  /    \      /
               \    /\                    /  \              /                        \/      \    / 
                \  /  \                  /    \            /                                  \  /  
                 \/    \                /      \          /                                    \/   
                        \        /\    /        \        /                                          
                         \      /  \  /          \      /                                           
                          \    /    \/            \    /                                            
                           \/\/                    \/\/                                             
'@)

# Test 11
,(11,@'
__________________________________________________
 Y     ||     YY     ||     YY         ||         
  \    ||    /  \    ||    /  \        /\         
   \   ||   /    \   ||   /    \      /  \    /\  
    \  ||  /      \  ||  /      \    /    \  /  \/
     \ || /        \ || /        \  /      \/     
      \||/          \||/          \/              
       \/            \/                           
'@,@'
_                                                 
 \            /\            /\                    
  \          /  \          /  \        /\         
   \        /    \        /    \      /  \    /\  
    \      /      \      /      \    /    \  /  \/
     \    /        \    /        \  /      \/     
      \  /          \  /          \/              
       \/            \/                           
'@)

# Test 12
,(12,@'
                                           /\  /\                      
                                          /  \/  \                    /
           /\                            /        \  /\              / 
    /\    /  \                          /          \/  \            /  
   /  \  /    \/\                      /                \    /\    /   
  /____\/________\                    /__________________\  /__\  /____
_)________________(__________________)____________________()____()_____
                   Y       ||       Y                                  
                    \      ||    /\/                                   
                     \  /\ ||   /                                      
                      \/  \||  /                                       
                           \| /                                        
                            \/                                         
'@,@'
                                           /\  /\                      
                                          /  \/  \                    /
           /\                            /        \  /\              / 
    /\    /  \                          /          \/  \            /  
   /  \  /    \/\                      /                \    /\    /   
  /    \/        \                    /                  \  /  \  /    
_/                \                  /                    \/    \/     
                   \                /                                  
                    \            /\/                                   
                     \  /\      /                                      
                      \/  \    /                                       
                           \  /                                        
                            \/                                         
'@)

# Test 13
,(13,@'
_____________)(____________)(_____________________
 Y    ||    Y  Y    ||    Y  Y   ||   YY    ||    
  \   ||   /    \   ||   /    \  ||  /  \   |/\  /
   \  ||  /      \  ||  /      \ || /    \  /  \/ 
    \ || /        \ || /        \||/      \/      
     \||/          \||/          \/               
      \/            \/                            
'@,@'
_            /\            /\                     
 \          /  \          /  \        /\          
  \        /    \        /    \      /  \    /\  /
   \      /      \      /      \    /    \  /  \/ 
    \    /        \    /        \  /      \/      
     \  /          \  /          \/               
      \/            \/                            
'@)

# Test 14
,(14,@'
            /\            /\                    
___________)__(__________)__(________)(_________
 Y   ||   Y    Y   ||   Y    Y      Y  Y    YY  
  \  ||  /      \  ||  /      \    /    \  /  \/
   \ || /        \ || /        \  /      \/     
    \||/          \||/          \/              
     \/            \/                           
'@,@'
            /\            /\                    
_          /  \          /  \        /\         
 \        /    \        /    \      /  \    /\  
  \      /      \      /      \    /    \  /  \/
   \    /        \    /        \  /      \/     
    \  /          \  /          \/              
     \/            \/                           
'@)

# Test 15
,(15,@'
           /\            /\                    
          /__\          /__\        /\         
_________)____(________)____(______)__(____)(__
 Y      Y      Y      Y      Y    Y    Y  Y  YY
  \    /        \    /        \  /      \/     
   \  /          \  /          \/              
    \/            \/                           
'@,@'
           /\            /\                    
          /  \          /  \        /\         
_        /    \        /    \      /  \    /\  
 \      /      \      /      \    /    \  /  \/
  \    /        \    /        \  /      \/     
   \  /          \  /          \/              
    \/            \/                           
'@)

# Test 16
,(16,@'
          /\            /\                    
         /  \          /  \        /\         
        /____\        /____\      /__\    /\  
_______)______(______)______(____)____(__)__()
 Y    Y        Y    Y        Y  Y      YY     
  \  /          \  /          \/              
   \/            \/                           
'@,@'
          /\            /\                    
         /  \          /  \        /\         
        /    \        /    \      /  \    /\  
_      /      \      /      \    /    \  /  \/
 \    /        \    /        \  /      \/     
  \  /          \  /          \/              
   \/            \/                           
'@)

# Test 17
,(17,@'
         /\            /\                    
        /  \          /  \        /\         
       /    \        /    \      /  \    /\  
      /______\      /______\    /____\  /__\/
_____)________(____)________(__)______()_____
 Y  Y          Y  Y          YY              
  \/            \/                           
'@,@'
         /\            /\                    
        /  \          /  \        /\         
       /    \        /    \      /  \    /\  
      /      \      /      \    /    \  /  \/
_    /        \    /        \  /      \/     
 \  /          \  /          \/              
  \/            \/                           
'@)

# Test 18
,(18,@'
        /\            /\                    
       /  \          /  \        /\         
      /    \        /    \      /  \    /\  
     /      \      /      \    /    \  /  \/
    /________\    /________\  /______\/_____
___)__________(__)__________()______________
 YY            YY                           
'@,@'
        /\            /\                    
       /  \          /  \        /\         
      /    \        /    \      /  \    /\  
     /      \      /      \    /    \  /  \/
    /        \    /        \  /      \/     
_  /          \  /          \/              
 \/            \/                           
'@)

# Test 19
,(19,@'
       /\            /\                    
      /  \          /  \        /\         
     /    \        /    \      /  \    /\  
    /      \      /      \    /    \  /  \/
   /        \    /        \  /      \/     
  /__________\  /__________\/______________
_)____________()___________________________
'@,@'
       /\            /\                    
      /  \          /  \        /\         
     /    \        /    \      /  \    /\  
    /      \      /      \    /    \  /  \/
   /        \    /        \  /      \/     
  /          \  /          \/              
_/            \/                           
'@)

# Test 20
,(20,@'
__________________________________________________
 Y     ||     YY     ||     YY         ||         
  \    ||    /  \    ||    /  \        /\         
   \   ||   /    \   ||   /    \      /  \    /\  
    \  ||  /      \  ||  /      \    /    \  /  \ 
     \ || /        \ || /        \  /      \/    \
      \||/          \||/          \/              
       \/            \/                           
'@,@'
_                                                 
 \            /\            /\                    
  \          /  \          /  \        /\         
   \        /    \        /    \      /  \    /\  
    \      /      \      /      \    /    \  /  \ 
     \    /        \    /        \  /      \/    \
      \  /          \  /          \/              
       \/            \/                           
'@)

# Test 21
,(21,@'
      /\            /\                    
     /  \          /  \        /\         
    /    \        /    \      /  \    /\  
   /      \      /      \    /    \  /  \/
  /________\    /________\  /______\/_____
_)__________(__)__________()______________
             YY                           
'@,@'
      /\            /\                    
     /  \          /  \        /\         
    /    \        /    \      /  \    /\  
   /      \      /      \    /    \  /  \/
  /        \    /        \  /      \/     
_/          \  /          \/              
             \/                           
'@)

# Test 22
,(22,@'
     /\            /\                    
    /  \          /  \        /\         
   /    \        /    \      /  \    /\  
  /______\      /______\    /____\  /__\/
_)________(____)________(__)______()_____
           Y  Y          YY              
            \/                           
'@,@'
     /\            /\                    
    /  \          /  \        /\         
   /    \        /    \      /  \    /\  
  /      \      /      \    /    \  /  \/
_/        \    /        \  /      \/     
           \  /          \/              
            \/                           
'@)

# Test 23
,(23,@'
                         /\                                 
                        /  \                                
                   /\  /    \                               
            /\    /  \/      \                              
           /  \  /            \                  /\         
          /____\/______________\                /__\        
_________)______________________(________)(____)____(_______
 Y      Y                        Y      Y  Y  Y      Y  YY  
  \    /                          \    /    \/        \/  \/
   \  /                            \  /                     
    \/                              \/                      
'@,@'
                         /\                                 
                        /  \                                
                   /\  /    \                               
            /\    /  \/      \                              
           /  \  /            \                  /\         
          /    \/              \                /  \        
_        /                      \        /\    /    \       
 \      /                        \      /  \  /      \  /\  
  \    /                          \    /    \/        \/  \/
   \  /                            \  /                     
    \/                              \/                      
'@)

# Test 24
,(24,@'
    /\            /\                    
   /  \          /  \        /\         
  /____\        /____\      /__\    /\  
_)______(______)______(____)____(__)__()
         Y    Y        Y  Y      YY     
          \  /          \/              
           \/                           
'@,@'
    /\            /\                    
   /  \          /  \        /\         
  /    \        /    \      /  \    /\  
_/      \      /      \    /    \  /  \/
         \    /        \  /      \/     
          \  /          \/              
           \/                           
'@)

# Test 25
,(25,@'
   /\            /\                    
  /__\          /__\        /\         
_)____(________)____(______)__(____)(__
       Y      Y      Y    Y    Y  Y  YY
        \    /        \  /      \/     
         \  /          \/              
          \/                           
'@,@'
   /\            /\                    
  /  \          /  \        /\         
_/    \        /    \      /  \    /\  
       \      /      \    /    \  /  \/
        \    /        \  /      \/     
         \  /          \/              
          \/                           
'@)

# Test 26
,(26,@'
  /\            /\                    
_)__(__________)__(________)(_________
     Y   ||   Y    Y      Y  Y    YY  
      \  ||  /      \    /    \  /  \/
       \ || /        \  /      \/     
        \||/          \/              
         \/                           
'@,@'
  /\            /\                    
_/  \          /  \        /\         
     \        /    \      /  \    /\  
      \      /      \    /    \  /  \/
       \    /        \  /      \/     
        \  /          \/              
         \/                           
'@)

# Test 27
,(27,@'
_)(____________)(_____________________
   Y    ||    Y  Y   ||   YY    ||    
    \   ||   /    \  ||  /  \   |/\  /
     \  ||  /      \ || /    \  /  \/ 
      \ || /        \||/      \/      
       \||/          \/               
        \/                            
'@,@'
_/\            /\                     
   \          /  \        /\          
    \        /    \      /  \    /\  /
     \      /      \    /    \  /  \/ 
      \    /        \  /      \/      
       \  /          \/               
        \/                            
'@)

# Test 28
,(28,@'
____________________________________
 Y     ||     YY         ||         
  \    ||    /  \        /\         
   \   ||   /    \      /  \    /\  
    \  ||  /      \    /    \  /  \/
     \ || /        \  /      \/     
      \||/          \/              
       \/                           
'@,@'
_                                   
 \            /\                    
  \          /  \        /\         
   \        /    \      /  \    /\  
    \      /      \    /    \  /  \/
     \    /        \  /      \/     
      \  /          \/              
       \/                           
'@)

# Test 29
,(29,@'
_____________________________
 Y            ||            Y
  \        /\ || /\      /\/ 
   \  /\  /  \||/  \  /\/    
    \/  \/    \/    \/       
'@,@'
_                            
 \                          /
  \        /\    /\      /\/ 
   \  /\  /  \  /  \  /\/    
    \/  \/    \/    \/       
'@)

# Test 30
,(30,@'
_____
 Y  Y
  \/ 
'@,@'
_    
 \  /
  \/ 
'@)

# Test 31
,(31,@'
       /\    
    /\/__\   
___)______(__
 YY        YY
'@,@'
       /\    
    /\/  \   
_  /      \  
 \/        \/
'@)

# Test 32
,(32,@'
      /\     
     /  \    
    /____\   
___)______(__
 YY        YY
'@,@'
      /\     
     /  \    
    /    \   
_  /      \  
 \/        \/
'@)

# Test 33
,(33,@'
_______
 Y    Y
  \/\/ 
'@,@'
_      
 \    /
  \/\/ 
'@)

# Test 34
,(34,@'
_)()()()()()()()()()()()()()()()()()(
'@,@'
_/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
'@)

) | % {
    $num, $expected, $s = $_
    $result = &$f $s
    $passed=$result-eq$expected
    "$num : $passed"
    # $result           # uncomment this line to display results

    $pass+=$passed
    $count+=1
}

"$pass/$count passed."

输出:

2 : True
1 : True
3 : True
4 : True
5 : True
6 : True
7 : True
8 : True
9 : True
10 : True
11 : True
12 : True
13 : True
14 : True
15 : True
16 : True
17 : True
18 : True
19 : True
20 : True
21 : True
22 : True
23 : True
24 : True
25 : True
26 : True
27 : True
28 : True
29 : True
30 : True
31 : True
32 : True
33 : True
34 : True
34/34 passed.

说明漫画:

Start here:
    /\                  /\                  /\        
   /  \                /  \                /  \       
  /    \              /    \              /    \      
_/      \            /      \            /      \     
         \          /        \          /        \    
          \        /          \        /          \   
           \      /            \      /            \  
            \    /              \    /              \ 
             \  /                \  /                \
              \/                  \/                  

Match and zoom it!
  /    \              /    \              /    \      $ceiling \
_/      \            /      \            /      \     $road    |  $outline
         \          /        \          /        \    $bottom  /

Start ceiling:
  /_   \              /_   \              /_   \      $ceiling \
_/      \            /      \            /      \     $road    |  $outline
         \          /        \          /        \    $bottom  /

Dig tunnels, build a road:
  /_   \              /_   \              /_   \      $ceiling \
_)______(____________)______(____________)______(_____$road    |  $outline
         \          /        \          /        \    $bottom  /

Attach to the road the top parts of pillars:
  /_   \              /_   \              /_   \      $ceiling \
_)______(____________)______(____________)______(_____$road    |  $outline
         \    ||    /        \    ||    /        \    $bottom  /

The road need support:
  /____\              /____\              /____\      $ceiling \
_)______(____________)______(____________)______(_____$road    |  $outline
         Y    ||    Y        Y    ||    Y        Y    $bottom  /

Put the road back into mountainous lands:
    /\                  /\                  /\        
   /  \                /  \                /  \       
  /_   \              /_   \              /_   \      $ceiling \
_)______(____________)______(____________)______(_____$road    |  $outline
         Y    ||    Y        Y    ||    Y        Y    $bottom  /
          \        /          \        /          \   
           \      /            \      /            \  
            \    /              \    /              \ 
             \  /                \  /                \
              \/                  \/                  

Build ceilings and build down pillars:
    /\                  /\                  /\        
   /  \                /  \                /  \       
  /__  \              /__  \              /__  \      
_)______(____________)______(____________)______(_____
         Y    ||    Y        Y    ||    Y        Y    
          \   ||   /          \   ||   /          \   
           \      /            \      /            \  
            \    /              \    /              \ 
             \  /                \  /                \
              \/                  \/                  

A few iterations later...
    /\                  /\                  /\        
   /  \                /  \                /  \       
  /____\              /____\              /____\      
_)______(____________)______(____________)______(_____
         Y    ||    Y        Y    ||    Y        Y    
          \   ||   /          \   ||   /          \   
           \  ||  /            \  ||  /            \  
            \ || /              \ || /              \ 
             \||/                \||/                \
              \/                  \/                  

Thanks. But our princess is in another castle!
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.