title: Check Number Is Perfect Square Using Additionsubtraction
signature: func checkNumberIsPerfectSquareUsingAdditionsubtraction(n int) bool {
test_code: package main
  
  import (
      "fmt"
      "reflect"
      "math"
      "sort"
  )
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  func validateSolution(actual bool, expected bool) bool {
      return reflect.DeepEqual(actual,expected)
  }
  
  func driver(n int, expected bool) string {
      if validateSolution(PLACEHOLDER_FN_NAME(n),expected) {
              return "PASSED"
      }
      return "FAILED"
  
  }
  
  func main() {
  
      // Use imports to avoid undefined errors
      var _ = reflect.DeepEqual
      _ = math.Abs
      _ = sort.Sort
      result := ""
      result = driver(1, true)
      fmt.Printf("TEST-0...%s\n", result)
      
      result = driver(4, true)
      fmt.Printf("TEST-1...%s\n", result)
      
      result = driver(9, true)
      fmt.Printf("TEST-2...%s\n", result)
      
      result = driver(25, true)
      fmt.Printf("TEST-3...%s\n", result)
      
      result = driver(36, true)
      fmt.Printf("TEST-4...%s\n", result)
      
      result = driver(3, false)
      fmt.Printf("TEST-5...%s\n", result)
      
      result = driver(121, true)
      fmt.Printf("TEST-6...%s\n", result)
      
      result = driver(14, false)
      fmt.Printf("TEST-7...%s\n", result)
      
      result = driver(17, false)
      fmt.Printf("TEST-8...%s\n", result)
      
      result = driver(80, false)
      fmt.Printf("TEST-9...%s\n", result)
      
          
  }
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;
  }