Skip to content
Permalink
Browse files

special case, check position for first ocurrencies (dont need to be r…

…ecursive)
  • Loading branch information...
franciscof5 committed May 9, 2018
1 parent dc9f1a7 commit b882a32de4b80b2ec6e1f2e43d90102f05acf323
Showing with 23 additions and 0 deletions.
  1. +23 −0 index.php
@@ -3,6 +3,7 @@
$text = $_GET['b1-b'];
function verifyBrackets($s) {
#simple counting
$open_t1 = substr_count($s, '(');
$open_t2 = substr_count($s, '{');
$open_t3 = substr_count($s, '[');
@@ -14,6 +15,28 @@ function verifyBrackets($s) {
if($open_t1!=$close_t1 || $open_t2!=$close_t2 || $open_t3!=$close_t3 )
$brackets_ok=false;
#special case, check position for first ocurrencies (dont need to be recursive)
if($open_t1 && $close_t1) {
$pt_o = strpos($s, '(');
$pt_c = strpos($s, ')');
if($pt_c<$pt_o)
$brackets_ok=false;
}
if($open_t2 && $close_t2) {
$pt_o = strpos($s, '{');
$pt_c = strpos($s, '}');
if($pt_c<$pt_o)
$brackets_ok=false;
}
if($open_t3 && $close_t3) {
$pt_o = strpos($s, '[');
$pt_c = strpos($s, ']');
if($pt_c<$pt_o)
$brackets_ok=false;
}
return $brackets_ok;
}
$brackets_ok=verifyBrackets($text);

0 comments on commit b882a32

Please sign in to comment.
You can’t perform that action at this time.