Skip to content

Instantly share code, notes, and snippets.

@dtjohnso
Created August 27, 2009 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dtjohnso/176329 to your computer and use it in GitHub Desktop.
Save dtjohnso/176329 to your computer and use it in GitHub Desktop.
Test to see if missing parentheses can be detected by a simple arithmetic count algorithm
Discussion @ http://andyanglea.com/blog/2009/08/if-problems
Error-free case:
12 1 23 4 3 2 3 4 3210 NO ERRORS
01 2 12 3 4 3 2 3 4321 NO ERRORS
if (($condition1 != $a) || ((len($condition2) == $b) && (!isset($_POST['submit'])))) {
Missing one ( case:
1* 0 12 3 2 1 2 3 210- ERROR DETECTED (ends with negative number)
1* 2 12 3 4 3 2 3 4321 ERROR DETECTED (ends with positive number)
if ( $condition1 != $a) || ((len($condition2) == $b) && (!isset($_POST['submit'])))) {
Missing one ) and one ( case:
12 * *3 4 3 2 3 4 3210 !UNDETECTABLE ERROR
01 * *2 3 4 3 2 3 4321 !UNDETECTABLE ERROR
if (($condition1 != $a || (len($condition2) == $b) && (!isset($_POST['submit'])))) {
Missing one ) and two ( case:
12 * ** 3 2 1 2 3 210- ERROR DETECTED (ends with negative number)
12 * ** 3 4 3 2 3 4321 ERROR DETECTED (ends with positive number)
if (($condition1 != $a || len($condition2) == $b) && (!isset($_POST['submit'])))) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment