橋とトンネル


32

新しい高速道路を構築するのはあなたの責任です。しかし、それは山岳地帯を通り抜けるため、多数の橋とトンネルが必要です。高速道路自体は単一のレベルにとどまる必要があります。

入力

次のように、標準入力で山がどのように見えるかの大まかなASCII記述が提供されます。

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

_最初の列マークで始まり、道路のレベル。山脈は連続しており、最後のセグメントが橋になる場合、偶数個の文字を持ちます。

入力行は100文字を超えることはなく、15行以下であると想定できます。すべての行の長さは同じで、最後にスペースが埋め込まれる可能性があります。道路は山の中や橋としては決して始まりません。入力の道路タイルに続く最初のものは、下り坂または上り坂です。

出力

出力は同じ山の範囲ですが、以前は最初だけだった道路があります。出力は標準出力で提供されます。

これには、多数のルールがあります。

  1. 道路は入力に示された場所から始まり、全体を通して同じレベルのままでなければなりません。簡単にするために、次のような既成の道路タイルを用意しました_

    _______
     \    /
      \/\/
    
  2. 道路は山脈の遠端まで延長する必要があります(つまり、入力ラインの長さが道路の距離を決定します)。

  3. 山が道路の行き先である場合は常に、トンネルを掘削する必要があります。トンネルは山を直進し、開始点と終了点に穴を残します(つまり、トンネルは山の斜面を開始点で閉じ括弧、終了点で開き括弧に置き換えます)。

  4. トンネルは、山にトンネルを残します。通常、このトンネルには天井があります。幸いなことに、トンネルが崩壊しないように、既成の道路タイルを使用して天井を補強することができます(トンネルの上の線はトンネル_を補強するために使用する必要があります)。

          /\
         /  \
        /____\
    ___)______(__
     \/        \/
    
  5. 山の高さが十分でない場合、トンネルを補強する必要はありません。私にとっても奇妙に聞こえますが、事前に作られた道路タイルは、その場合に間隔をあけても保持するのに十分強いと言われています(トンネルの真上に傾斜がある場合、トンネルの天井は描かれません):

           /\
        /\/__\
    ___)______(__
     \/        \/
    
  6. 道路が割れ目を横切る必要があるときはいつでも橋が必要です。短い橋の場合、既成の道路タイルは十分に強力ですが、橋の最初と最後にまだ少しサポートが必要です(橋の下の最初の下り坂と最後の上り坂が置き換えられY、橋の支持梁があります):

    _____
     Y  Y
      \/
    
  7. 長いブリッジには追加のサポートが必要です。長い橋とは、サポートされていない道路タイルが6つ以上連続して並んでいる橋です。長い橋の中心には柱が必要です。柱は、次のような既成の柱梁で簡単に構築できます|。各柱にはそれらのうちの2つが必要で、それらは溝の底まで延びています。

    _____________________________
     Y            ||            Y
      \        /\ || /\      /\/ 
       \  /\  /  \||/  \  /\/    
        \/  \/    \/    \/       
    
  8. 入力は、高速道路の建設に必要な全山脈の一部のみを表すため、橋またはトンネルの途中で突然終了する場合があります。長いブリッジルールは最終セグメントに適用され、指定された入力を超える最初の部分がブリッジを再びサポートすると想定できます。

上記のルールに従って、入力に対して以下を取得します。

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

文字数による最短コードが優先されます。行の末尾の空白は、検証のために無視されます。

サンプル入力1

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

サンプル出力1

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

サンプル入力2

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

サンプル出力2

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

注意

出力の末尾のスペースは、参照ソリューションとの比較のために無視されます。

勝利条件

ゴルフで通例であるように、最短のコードが勝ちます。同点の場合、以前のソリューションが優先されます。

テストケース

同じテストケースを含む2つのテストスクリプトがあります。

呼び出しはどちらの場合でも:<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
注:一部のテストケースの上部に意図しない空の行が含まれるテストスクリプトを更新しました。今すぐ修正する必要があります。
ジョーイ

回答:


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テストスクリプトを変更する必要もあります。

-   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に感謝します。私は彼が作成したものを取り、それがいくらか機能するまでそれをashりました;-)
ジョーイ

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
いいね。それはすべての部分でかなり悪そうに見えます;-)。なぜPerlの人々は常にすべてを正規表現で解決しなければならないのですか?:-þ–
ジョーイ

レジスは真のPerlハッカーの武器だからです:ð
FUZxxl

2
perlハッカー(私は自分のことを何年も前に過ぎ去ったと言います)は、ジョーイ:正規表現で問題を解決できるのなら、なぜ他のことに悩むのでしょうか?これは本当に正規表現にとって理想的な問題だと思います。それは、自分でバックトラッキングステートマシンを実装することです。
ブースバイ

それは完全に深刻な意味ではありませんでした。私自身の参照ソリューションは、当初も多くの正規表現を使用していました。
ジョーイ

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;}

これはそれであるはずです、私はパワーシェルスクリプトでこれをテストしましたので、それは大丈夫です...

編集1

すべてのchar定数を数字に置き換え、std :: coutへの連続呼び出し+その他のいくつかの小さな変更を削除しました。

編集2

最後の編集で、600未満になりました。g[t] [f]を#defineとして取り出し、いくつかの点を移動しました。


うん、いくつかのテストケースが間違っていたが、それは私自身のせいだ。よさそうだ:-)
ジョーイ

それは役立ち#define std::ますか?
FUZxxl

@FUZxxl、私はそうは思わない、私は「std ::」を4回しか使用しないので20文字です、定義を使用した場合、それらの場所のそれぞれに2文字が必要になります::)定義には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)。条件に&&演算子が含まれる場合、括弧とaを使用して否定する必要があります!を使用か、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

テストは大丈夫です-テストスクリプトを貼り付けている間に台無しにしてしまいました...厄介です。
アレクシYrttiaho

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

アーラン、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.

まったく競争力がない。正直に言うと、私は単にゴルフではなく、素敵なアスキーアートの制作に興味がありました。これは正規表現を使用しないことに注意してください。代わりに、私は自分でステートマシンを作成しました。これには、上記のperlソリューションで説明したシェルスクリプトのオーバークォート修正も必要です。


1

Powershell、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!
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.