title: Check Number Is Perfect Square Using Additionsubtraction
signature: function checkNumberIsPerfectSquareUsingAdditionsubtraction($n) {
test_code: <?php
  
  
  // SOLUTION CODE 
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  function validateSolution($actual, $expected){
      return serialize($actual) == serialize($expected);
  }
  
  function driver($n, $expected){
      try{
        if (validateSolution(PLACEHOLDER_FN_NAME($n), $expected)){
          return "PASSED";
        }
        return "FAILED";
      }
      catch (Exception $exception_obj) {
        return get_class($exception_obj);
      }
  }
  
  function main(){
      printf("TEST-0...%s\n",driver(
        1, 
        true));
      
      printf("TEST-1...%s\n",driver(
        4, 
        true));
      
      printf("TEST-2...%s\n",driver(
        9, 
        true));
      
      printf("TEST-3...%s\n",driver(
        25, 
        true));
      
      printf("TEST-4...%s\n",driver(
        36, 
        true));
      
      printf("TEST-5...%s\n",driver(
        3, 
        false));
      
      printf("TEST-6...%s\n",driver(
        121, 
        true));
      
      printf("TEST-7...%s\n",driver(
        14, 
        false));
      
      printf("TEST-8...%s\n",driver(
        17, 
        false));
      
      printf("TEST-9...%s\n",driver(
        80, 
        false));
      
  }
  
  main();
  ?>
source_py: def check_number_is_perfect_square_using_additionsubtraction(n):
      i = 1
      the_sum = 0
      while (the_sum < n):
          the_sum += i
          if (the_sum == n):
              return True
          i += 2
      return False
source_cpp: bool check_number_is_perfect_square_using_additionsubtraction(int n) {
    for ( int sum = 0, i = 1;
    sum < n;
    i += 2 ) {
      sum += i;
      if ( sum == n ) return true;
    }
    return false;
  }