箭头指向哪里?


32

箭头指向哪里?

在此挑战中,您的目标是跟随箭头并输出其指向的字符。

例子

输入:

d  S------+    b
          |     
          |     
   c      +--->a

输出: a


输入:

S-----+---a->c
      |       
      V       
      b       

输出: b

箭头未指向,c因为它被分隔a,这意味着该路径永远不会导致箭头。


输入:

a S      s
  |      |
  V      V
  b      c

输出: b


输入:

d s<+S+--V
    |||  Q
    -++   

输出: Q

此路径从开始S,向下,向右,向上,向右,然后指向Q。请注意,路径并非直接从S+


输入:

d s-+   +-S  +--+
    +-->b |  |  |
     |  | +--+  |
     +--+ A<----+

输出: A


输入:

S-----+   
|     +-^ 
+---+->B  
    +---^ 

输出: B

因为有效行永远不会导致空白字符。唯一不会导致空格字符的行会导致B

挑战

输入将是多行字符串,您需要在其中找到箭头指向的字符。只有一个有效的箭头。有效箭头指向不包含的字母数字字符S。一条线永远不会重叠。例如-|-

  • S (大写)表示箭头的起点。
  • - 代表一条水平线
  • +表示轴可能发生变化。有效箭头永远不会以开头+
  • | 代表垂直线
  • > < V ^这些中的任何一个都代表箭头。这些将永远不会连接到+

S字符串中将只有一个。输入也将填充为矩形(不一定是正方形)。


1
“这永远不会出现在旁边S。” 可能应该改写为“这将永远不是箭头的第一个字符”。(因为该Q示例 +与相邻S。)“ +表示轴的变化”。最好是“ +代表轴可能发生变化”。(因为该B示例显示您可以在+不改变方向的情况下移动。)否则,将是一个不错的挑战。:)
Martin Ender

我对您的一个测试用例进行了更改。我认为,这将使它更难写程序,只有发生,以获得正确的答案,像我那样在第一。
El'endia Starman

箭头可以改变方向---^吗?换句话说,如果在B示例中,B可以留在第一行吗?
edc65

@ edc65是指像Q示例一样?
Downgoat

1
箭头将不会连接到“ +”。但是可以将其连接到“ S”吗?是否S>a有效?
edc65

Answers:


9

的JavaScript(ES6),195 245 231 242 246 250

Edit4现在,一个递归函数。可能不能再打高尔夫球

Edit3测试直线,并测试合并​​在T功能中的箭头,并删除S和H功能。

EDIT2修订和更长:(之后本澄清

编辑小改进,在这里和那里切一些字符,等待CJammers介入

测试在符合EcmaScript 6的浏览器中运行以下代码段的方法。(可在Firefox上使用。Chrome仍然缺少传播操作符...

f=(s,p=s[I='indexOf']`S`,w=m=[o=~s[I]`
`,1,-o,-1],q,v,r)=>m.some((d,i)=>{for(v=w,q=p;r=s[q+=d],r=='|-'[i&1];)v='+';return r=r==v?f(s,q,v):/\w/.test(r=s[q+m['^>V<'[I](r)]])&&r},s=[...s],s[p]=0)&&r


// Less golfed
// U: recursive scan function
U = (s, // input string or array
     p = s.indexOf`S`, // current position, defult to position of S into string (at first call)
     w = // char to compare looking for a '+', at first call default to garbage as you can't follow '+' near 'S'
       m = [// m, global, offset array form movements. 
         o = ~s.indexOf`\n`, // o, global, row line +1 (negated)
         1, -o, -1], // complete the values of m array
     // m and o are assigned again and again at each recursive call, but that is harmless
     // params working as local variables as the function is recursive
     q,v,r) => 
{
   s = [...s]; //convert to array, as I have to modify it while scanning
     //the conversion is done again and again at each recursive call, but that is harmless
   s[p] = 0; // make s[p] invalid to avoid bouncing back and forth
  
   m.some( // for each direction, stop if endpoint found
      (d,i ) => {
        q = p; // start at current position, then will add the offset relative to current direction
        v = w; // for each direction, assign the starting value that can be '+' or garbage at first call
        // compare char at next position with the expected char based on direction (- for horiz, | for vertical)
        // in m array, values at even positon are vertical movements, odds are horizontal
        while (s[q+=d] == '|-'[i&1]) // while straight direction, follow it until it ends
          v = '+'; // from now on '+' is allowed
        r = s[q];
        if (r == v) // check if found a '+'
          r = U(s, q, v) // recursive call to check all directions from current position
        else
        {
          r = s[q + m['^>V<'.indexOf(r)]], // pointed char in p (if arrowhead, else will return undefined)
          r = /\w/.test(r) && r // if alphanumeric, then we found our result - else r = false
        }  
        return r; // returning r to .some; if r is truthy, the .some function will stop
      }
   ) 
   return r; // result if found, else undefined or null
}

// TEST
out=x=>O.innerHTML+=x.replace(/</g,'&#60;')+'\n'

// Using explicit newlines '\n' to ensure the padding to a rectangle
;[
 ['z<+S-+->a','a'] 
,['a<-+S>b','b']
,['S-+\n  |\n  V\n  a','a']
,['a S      s\n  |      |\n  V      V\n  b      c  ','b']
,['S-----+  \n|     +-^  \n+---+->B \n    +---^','B']
,['d s<+S+--V\n    |||  Q\n    -++    ','Q']
,['d s-+   +-S  +--+\n    +-->b |  |  |\n     |  | +--+  |\n     +--+ A<----+  ','A']
,['S-----+   \n|     +-^ \n+---+->B  \n    +---^ ','B']
].forEach(t=>{
  r=f(t[0])
  k=t[1]
  out('Test '+(r==k?'OK':'Fail')+'\n'+t[0]+'\nResult: '+ r +'\nCheck: '+k+'\n')
})
<pre id=O></pre>


5

JavaScript 2016,264263249240240 235 234字节

在Firefox中运行它:

m=l=>{o=(q,e)=>q.indexOf(e)
s=[-1,1,c=~o(l,`
`),-c]
f=i=>!o[i]&(!(r=l[i+s[o(a="<>^V",o[i]=c=l[i])]])|r<"0"|r>"z"|r=="S"||alert(s=r))&&c&&[for(j of (c!='+'?a:"")+"-|+")for(k of s)l[i+k]!=j|~o(l[i]+j,k*k>1?"-":"|")||f(i+k)]
f(o(l,'S'))}

m(`d s-+   +-S  +--+
    +-->b |  |  |
     |  | +--+  |
     +--+ A<----+`)

分散在我的一些笔记中:

m=l=>{o=(q,e)=>q.indexOf(e) //shorthand for indexOf
s=[-1,1,c=o(l,`
`)+1,-c] // get all possible moves in 1d
w=[] // to keep track of the already-visited indexes
f=i=>{c=l[i] // current character
if(!w[i]&&c) // only continue if the index wasn't already visited and we aren't out of bounds
{r=l[i+s[o(a="<>^V",w[i]=c)]] // sets w[i] to a truthy value and maps the arrows to their corresponding moves in s. If c is an arrow, r is the character it's pointing to.
if(!r||r<"0"||r>"z"||r=="S"||alert(r)) // if r is an alphanumeric character that isn't r, show it and return. If not, continue.
for(j of (c!='+'?a:"")+"-|+") // iterate over all characters to make sure plusses are checked out last, which is necessary at the start.
for(k of s) // check out all possible moves
l[i+k]!=j|| // check if the move leads to the character we're looking for
~o(l[i]+j,k*k>1?"-":"|")|| // make sure the current nor that character goes against the direction of the move
f(i+k)}} // make the move, end of f
f(o(l,'S'))} // start at S

您可以这样做o = 'indexOf',然后再q[o](e)使用时可以节省一些时间。
不是查尔斯(Charles)

同样,在代码高尔夫中,for(;;)循环通常是最有效的。在这种情况下可能是错误的,但是请尝试一下。
不是查尔斯(Charles)

1
测试用例a<-+S->b,我认为它应该给b只,作为一个有效的箭头将永远不会有一个+启动
edc65

修复该问题,并将f变成单线。顺便说一句,我真的很喜欢您的方法。
bopjesvla

旁注:我真的很喜欢数组理解,但是它不再适用于EcmaScript标准的任何版本。我建议给您标记anser JavaScript 2016(激励一个有效且良好的答案,而不是问题)
edc65

3

VBA Excel 2007,894个字节

好吧,这开始好得多,然后结束了。我感觉我的逻辑有缺陷,如果我重新排序一些逻辑,我可以节省一吨字节,但是这个= P已经花了太多时间

输入的内容是您正在使用的任何工作表的A列。该方法利用了Excel具有良好的网格并将所有内容分解的事实,因此您可以更清楚地看到它在做什么。

Sub m()只是从列A中获取复制粘贴的数据并按char将其分解。如果我们允许修改的输入,那么如果您将迷宫预先格式化为每个单元格1个字符,则可以通过删除以下内容来节省一些字节sub m()

将任意大小的迷宫粘贴到Excel中,最大尺寸为99行,宽为27个字符。如果您想要更大的迷宫,它只需增加2个字节即可将范围扩大到999行和ZZ列

还可能需要法官来判断Excel工作表对于VBA答案是否有效“标准输入”。如果不是这样,几乎不可能为“即时窗口”提供VBA多行输入

要运行此代码,只需将此代码粘贴到Excel模块中,将迷宫粘贴到A1中并运行 sub j()

Sub m()
For k=1 To 99
u=Cells(k,1).Value
For i=1 To Len(u)
Cells(k,i+1).Value=Mid(u,i,1)
Next
Next
Columns(1).Delete
End Sub
Sub j()
m
With Range("A:Z").Find("S",,,,,,1)
h .row,.Column,0
End With
End Sub
Sub h(r,c,t)
If t<>1 Then l r-1,c,1,0,r
If t<>-1 Then l r+1,c,-1,0,r
If t<>2 Then l r,c-1,2,0,r
If t<>-2 Then l r,c+1,-2,0,r
End Sub
Sub l(r,c,y,p,i)
On Error GoTo w
q=Cells(r,c).Text
If q="V" Or q="^" Or q="<" Or q=">" Then
p=1
End If
f="[^V<>]"
If p=1 And q Like "[0-9A-UW-Za-z]" Then
MsgBox q: End
Else
If q="^" Then p=1: GoTo t
If q="V" Then p=1: GoTo g
If q="<" Then p=1: GoTo b
If q=">" Then p=1: GoTo n
Select Case y
Case 1
t:If q="|" Or q Like f Then l r-1,c,y,p,q
Case -1
g:If q="|" Or q Like f Then l r+1,c,y,p,q
Case 2
b:If q="-" Or q Like f Then l r,c-1,y,p,q
Case -2
n:If q="-" Or q Like f Then l r,c+1,y,p,q
End Select
If q="+" And i<>"S" Then h r,c,y*-1
p=0
End If
w:
End Sub

2

Python 3,349字节

哎呀,这么多字节。

S=input().split('\n')
Q=[[S[0].find('S'),0]]
D=[[1,0],[0,1],[-1,0],[0,-1]]
A='-S--++-'
B='|S||++|'
P='>V<^'
i=0
while D:
 a,b=Q[i];i+=1
 j=S[b][a]
 for x,y in D:
  try:
   c,d=a+x,b+y;k=S[d][c]
   if k in P:
    z=P.index(k);print(S[d+D[z][1]][c+D[z][0]]);D=[]
   if (j+k in A and x)+(j+k in B and y)*~([c,d]in Q):Q+=[[c,d]]
  except IndexError: pass

本质上是广度优先的搜索。奖励:实际上exit(),它会正常退出,而不是使用,反而会更长。


伙计,这没有实现约一半的搜索约束。ideone.com/OzoWRX
bopjesvla

@bopjesvla:德拉特,你是对的。好地方!
El'endia Starman

如何与一起使用多行字符串input()?对我来说有问题。
The_Basset_Hound

@The_Basset_Hound:您不能手动输入换行符;您必须立即复制粘贴整个内容。
El'endia Starman

@ El'endiaStarman我正在复制/粘贴,它仍然只读取看来的第一行。
The_Basset_Hound

2

Perl 5

结果比其他解决方案更长。
即使打了高尔夫球。这是非高尔夫版本。
它会打印地图,以便您可以跟随光标。

它的工作方式?在每个步骤中,它都会在堆栈上放置可能的移动。并且它将一直运行,直到堆栈上没有剩余的任何东西,或者找到了解决方案。
可以轻松地对其进行修改以查找所有解决方案并选择最近的-> while(@_){...

while(<>){
  chomp;
  @R=split//;
  $j++;$i=0;
  for(@R){$nr++;$i++;$A[$i][$j]=$_;if('S'eq$_){$x=$i;$y=$j}}
  $xm=$i,if$xm<$i;$ym=$j;
}
push(@_,[($x,$y,'S',0)]);
$cr='';
while(@_&&''eq$cr){
 @C=pop@_;
 ($x,$y,$d,$n)=($C[0]->[0],$C[0]->[1],$C[0]->[2],$C[0]->[3]);
 $c=$A[$x][$y];
 $A[$x][$y]='.';
 if($c=~m/[S+]/){
    if('L'ne$d&&$A[$x+1][$y]=~m/[+-]/){push(@_,[($x+1,$y,'R',$n+1)])}
    if('D'ne$d&&$A[$x][$y-1]=~m/[+|]/){push(@_,[($x,$y-1,'U',$n+1)])}
    if('R'ne$d&&$A[$x-1][$y]=~m/[+-]/){push(@_,[($x-1,$y,'L',$n+1)])}
    if('U'ne$d&&$A[$x][$y+1]=~m/[+|]/){push(@_,[($x,$y+1,'D',$n+1)])}
 }
 if($c eq'|'){
    if($d ne'U'&&$A[$x][$y+1]=~m/[+|<>^V]/){push(@_,[($x,$y+1,'D',$n+1)])}
    if($d ne'D'&&$A[$x][$y-1]=~m/[+|<>^V]/){push(@_,[($x,$y-1,'U',$n+1)])}
 }
 if($c eq'-'){
    if($d ne'L'&&$A[$x+1][$y]=~m/[+-<>^V]/){push(@_,[($x+1,$y,'R',$n+1)])}
    if($d ne'R'&&$A[$x-1][$y]=~m/[+-<>^V]/){push(@_,[($x-1,$y,'L',$n+1)])}
 }
 if($c=~m/[<>^V]/&&$n<$nr){
    if($c eq'>'&&$A[$x+1][$y]=~m/\w/){$cr=$A[$x+1][$y];$nr=$n}
    if($c eq'<'&&$A[$x-1][$y]=~m/\w/){$cr=$A[$x-1][$y];$nr=$n}
    if($c eq'V'&&$A[$x][$y+1]=~m/\w/){$cr=$A[$x][$y+1];$nr=$n}
    if($c eq'^'&&$A[$x][$y-1]=~m/\w/){$cr=$A[$x][$y-1];$nr=$n}
 }
 print_map()
}
print "$cr\n";
sub print_map {
    print "\033[2J"; #clearscreen
    print "\033[0;0H"; #cursor at 0,0
    for$j(1..$ym){for$i(1..$xm){print (($x==$i&&$y==$j)?'X':$A[$i][$j])}print"\n"}
    sleep 1;
}

测试

$ cat test_arrows6.txt
S-----+
|     +-^
+---+->B
    +---^

$ perl arrows.pl < test_arrows6.txt
.-----+
.     +-^
......XB
    .....
B

2
我看到标题并想到了“ Perl”和“完成了5个字节”。心脏病发作
Conor O'Brien 2015年

2

PHP版本(注释为法语,对不起)

<?php
/*
* By Gnieark https://blog-du-grouik.tinad.fr oct 2015
* Anwser to "code golf" http://codegolf.stackexchange.com/questions/57952/where-is-the-arrow-pointing in PHP
*/
//ouvrir le fichier contenant la "carte et l'envoyer dans un array 2 dimmension
$mapLines=explode("\n",file_get_contents('./input.txt'));
$i=0;
foreach($mapLines as $ligne){
    $map[$i]=str_split($ligne,1);
    if((!isset($y)) && in_array('S',$map[$i])){
        //tant qu'à parcourir la carte, on cherche le "S" s'il n'a pas déjà été trouvé.
        $y=$i;
        $x=array_search('S',$map[$i]);
    }
    $i++;
}
if(!isset($y)){
    echo "Il n'y a pas de départ S dans ce parcours";
    die;
}
echo "\n".file_get_contents('./input.txt')."\nLe départ est aux positions ".$map[$y][$x]." [".$x.",".$y."]. Démarrage du script...\n";
$previousX=-1; // Contiendra l'ordonnée de la position précédente. (pour le moment, une valeur incohérente)
$previousY=-1; // Contiendra l'absycede la position précédente. (pour le moment, une valeur incohérente)
$xMax=count($map[0]) -1;
$yMax=count($map) -1;
$previousCrosses=array(); //On ne gardera en mémoire que les croisements, pas l'ensemble du chemin.
while(1==1){ // C'est un défi de codagee, pas un script qui sera en prod. j'assume.
    switch($map[$y][$x]){
        case "S":
            //même fonction que "+"
        case "+":
            //on peut aller dans les 4 directions
            $target=whereToGoAfterCross($x,$y,$previousX,$previousY);
            if($target){
          go($target[0],$target[1]);
            }else{
          goToPreviousCross();
            }
            break;
        case "s":
            goToPreviousCross();
            break;
        case "-":
        //déplacement horizontal
        if($previousX < $x){
          //vers la droite
          $targetX=$x+1;
          if(in_array($map[$y][$targetX],array('-','+','S','>','^','V'))){
        go($targetX,$y);
          }else{
        //On est dans un cul de sac
        goToPreviousCross();
          }
        }else{
          //vers la gauche
          $targetX=$x-1;
          if(in_array($map[$y][$targetX],array('-','+','S','<','^','V'))){
        go($targetX,$y);
          }else{
        //On est dans un cul de sac
        goToPreviousCross();
          }
        }
            break;
        case "|":
        //déplacement vertical
        if($previousY < $y){
          //on descend (/!\ y augmente vers le bas de la carte)
          $targetY=$y+1;
          if(in_array($map[$targetY][$x],array('|','+','S','>','<','V'))){
        go ($x,$targetY);
          }else{
        goToPreviousCross();
          }
        }else{
        //on Monte (/!\ y augmente vers le bas de la carte)
          $targetY=$y - 1;
          if(in_array($map[$targetY][$x],array('|','+','S','>','<','V'))){
        go ($x,$targetY);
          }else{
        goToPreviousCross();
          } 
        }
            break;
    case "^":
    case "V":
    case ">":
    case "<":
      wheAreOnAnArrow($map[$y][$x]);
      break;
    }
}
function wheAreOnAnArrow($arrow){
  global $x,$y,$xMax,$yMax,$map;
  switch($arrow){
    case "^":
      $targetX=$x;
      $targetY=$y -1;
      $charsOfTheLoose=array(" ","V","-","s");
      break;
    case "V":
      $targetX=$x;
      $targetY=$y + 1;
      $charsOfTheLoose=array(" ","^","-","s");
      break;
    case ">":
      $targetX=$x + 1;
      $targetY=$y;
      $charsOfTheLoose=array(" ","<","|","s");   
      break;
    case "<":
      $targetX=$x - 1;
      $targetY=$y;
      $charsOfTheLoose=array(" ",">","|","s");   
      break;
    default:     
      break;
  }
  if(($targetX <0) OR ($targetY<0) OR ($targetX>$xMax) OR ($targetY>$yMax) OR (in_array($map[$targetY][$targetX],$charsOfTheLoose))){
      //on sort du cadre ou on tombe sur un caractere inadapté
      goToPreviousCross();
  }else{
    if(preg_match("/^[a-z]$/",strtolower($map[$targetY][$targetX]))){
      //WIN
      echo "WIN: ".$map[$targetY][$targetX]."\n";
      die;
     }else{
      //on va sur la cible
      go($targetX,$targetY);
     }
  }
}
function whereToGoAfterCross($xCross,$yCross,$previousX,$previousY){

            //haut
            if(canGoAfterCross($xCross,$yCross +1 ,$xCross,$yCross,$previousX,$previousY)){
                return array($xCross,$yCross +1);
            }elseif(canGoAfterCross($xCross,$yCross -1 ,$xCross,$yCross,$previousX,$previousY)){
                //bas
                return array($xCross,$yCross -1);
            }elseif(canGoAfterCross($xCross-1,$yCross,$xCross,$yCross,$previousX,$previousY)){
                //gauche
                return array($xCross-1,$yCross);
            }elseif(canGoAfterCross($xCross+1,$yCross,$xCross,$yCross,$previousX,$previousY)){
                //droite
                return array($xCross+1,$yCross);
            }else{
          //pas de direction possible
          return false;
            }  
}
function canGoAfterCross($xTo,$yTo,$xNow,$yNow,$xPrevious,$yPrevious){
    global $previousCrosses,$xMax,$yMax,$map;
    if(($xTo < 0) OR ($yTo < 0) OR ($xTo >= $xMax) OR ($yTo >= $yMax)){return false;}// ça sort des limites de la carte
    if(
    ($map[$yTo][$xTo]==" ") // on ne va pas sur un caractere vide
    OR (($xTo==$xPrevious)&&($yTo==$yPrevious)) //on ne peut pas revenir sur nos pas (enfin, ça ne servirait à rien dans cet algo)
    OR (($xTo==$xNow)&&($map[$yTo][$xTo]=="-")) //Déplacement vertical, le caractere suivant ne peut etre "-"
    OR (($yTo==$yNow)&&($map[$yTo][$xTo]=="|")) // Déplacement horizontal, le caractère suivant ne peut être "|"
    OR ((isset($previousCrosses[$xNow."-".$yNow])) && (in_array($xTo."-".$yTo,$previousCrosses[$xNow."-".$yNow]))) //croisement, ne pas prendre une direction déjà prise
   ){    
      return false;
    }
    return true;    
}
function go($targetX,$targetY){
    global $previousX,$previousY,$x,$y,$previousCrosses,$map;
    if(($map[$y][$x]=='S')OR ($map[$y][$x]=='+')){
        //on enregistre le croisement dans lequel on renseigne la direction prise et la direction d'origine
        $previousCrosses[$x."-".$y][]=$previousX."-".$previousY;
        $previousCrosses[$x."-".$y][]=$targetX."-".$targetY; 
    }
    $previousX=$x;
    $previousY=$y;
    $x=$targetX;
    $y=$targetY;
    //debug
    echo "deplacement en ".$x.";".$y."\n";   
}
function goToPreviousCross(){
  global $x,$y,$previousX,$previousY,$xMax,$yMax,$previousCrosses;

  /*
  * On va remonter aux précédents croisements jusqu'à ce 
  * qu'un nouveau chemin soit exploitable
  */
  foreach($previousCrosses as $key => $croisement){
    list($crossX,$crossY)=explode("-",$key);
    $cross=whereToGoAfterCross($crossX,$crossY,-1,-1);
    if($cross){
      go($crossX,$crossY);
      return true;
    } 
  }
  //si on arrive là c'est qu'on est bloqués
  echo "Aucun chemin n'est possible\n";
  die;
}

1

Haskell,268个字节

恭喜您!放弃赏金,但这就是我得到的。可能/可能并非在所有情况下都有效,但+据我所知,实际上可以处理以箭头开头和指向es的箭头。甚至不包括搜索,这S只是(0,0)现在。

import Data.List
x%m=length m<=x||x<0
a s(x,y)z|y%s||x%(head s)=[]|0<1=b s(x,y)z$s!!y!!x
b s(x,y)z c|g c>[]=filter(>' ')$concat[a s(x+i k,y+i(3-k))k|k<-g c,k-z`mod`4/=2]|0<1=[c]
i=([0,-1,0,1]!!)
g c=findIndices(c`elem`)$words$"V|+S <-+S ^|+S >-+S"
f s=a(lines s)(0,0)0

0

我希望看到本着https://www.youtube.com/watch?v=a9xAKttWgP4的APL版本

首先,我想可以将矢量化的Julia解决方案按1:0.3转换为APL或J。它采用代表R x K箭图的字符串R。它首先将符号矩阵转换为3x3小型矩阵,其模式是字符串“ \ 0 \ x18 \ fH \ t]] \ x1cI”的字母的二进制扩展。例如,“ +”被编码为reshape([0,digits(int(']'),2,8)],3,3)

  0 2 0
  2 2 2
  0 2 0

在此表示形式中,路径由2组成,从起点开始被3淹没。

A=zeros(Int,L*3+3,K*3+3)
s(i,j=i,n=2)=A[i:end+i-n,j:end+j-n]
Q=Int['A':'Z';'a':'z']
for k=0:K-1,l=0:L-1
r=R[K*l+k+1]
q=search(b"V^><+S|-",r)
d=reverse(digits(b"\0\x18\fH\t]]\x1cI"[q+1],2,8))
A[1+3l:3l+3,1+3k:3k+3]=2*[d;0]
A[3l+2,3k+2]+=r*(r in Q&&r!='V'&&r!='^')+(1-r)*(r=='S')+3(5>q>0)
end
m=0
while sum(A)>m
m=sum(A)
for i=0:1,j=1:2,(f,t)=[(3,6),(11,15)]
A[j:end+j-2,j:end+j-2]=max(s(j),f*(s(j).*s(2-i,1+i).==t))
end
end
for i=[1,4],k=Q
any(s(1,1,5).*s(5-i,i,5).==11*k)&&println(Char(k))
end

去测试,

   R=b"""
       d  S------+    b
                 |     
                 |     
          c      +--->a
       """;

   K=search(R,'\n') # dimensions
   L=div(endof(R),K)


   include("arrow.jl")

a

顺便说一句,我认为子句“另一个+可能相邻,但箭头应优先处理-或|首先”。向量方法处于不利地位。无论如何,我只是忽略了它。

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.