title: Find A Triplet That Sum To A Given Value 1
signature: class Solution {
  
      public bool FindATripletThatSumToAGivenValue1(List<int> a, int arr_size, int sum) {
test_code: using System;
  using System.Numerics;
  using System.Diagnostics;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Security.Cryptography;
  using System.Web.UI;
  using System.Web.Script.Serialization;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  namespace EvaluatePrediction {
      class TestRunner {
          public bool ValidateSolution(bool actual, bool expected){
              return new JavaScriptSerializer().Serialize(actual) == new JavaScriptSerializer().Serialize(expected);
          }
  
          public string driver(List<int> a, int arr_size, int sum, bool expected){
              try{
                PLACEHOLDER_CLS_NAME solution_cls = new PLACEHOLDER_CLS_NAME();
                bool pred_result = solution_cls.PLACEHOLDER_FN_NAME(a, arr_size, sum); 
                if (ValidateSolution(
                      pred_result,
                      expected)){
                  return "PASSED";
                }
                return "FAILED";
              } 
              catch (Exception exception_obj)
              {
                return exception_obj.GetType().FullName;
              }
          }
          static void Main(string[] args) {
              TestRunner runner = new TestRunner();
              String result;
              result = runner.driver(
                  new List<int>{28, 47, 65, 89}, 3, 3, 
                  false
              );
              Console.WriteLine(string.Format(
                  "TEST-0...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-90, -88, -88, -70, -66, -64, -64, -56, -52, -48, -42, -40, -26, -16, -14, -8, -2, 0, 6, 12, 12, 14, 18, 46, 50, 52, 52, 52, 58, 68, 70, 70, 74, 78, 84, 96, 98}, 22, 24, 
                  true
              );
              Console.WriteLine(string.Format(
                  "TEST-1...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0}, 0, 0, 
                  false
              );
              Console.WriteLine(string.Format(
                  "TEST-2...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{22, 49, 52, 54, 66, 80, 87, 93}, 5, 7, 
                  false
              );
              Console.WriteLine(string.Format(
                  "TEST-3...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-96, -92, -86, -74, -62, -60, -56, -54, -46, -38, -32, -26, -16, -16, -8, -4, 0, 6, 20, 28, 42, 44, 56}, 13, 19, 
                  false
              );
              Console.WriteLine(string.Format(
                  "TEST-4...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 39, 39, 
                  false
              );
              Console.WriteLine(string.Format(
                  "TEST-5...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{1, 2, 16, 16, 20, 24, 24, 38, 41, 54, 57, 72, 79, 83, 89, 90, 96, 97, 98}, 12, 12, 
                  false
              );
              Console.WriteLine(string.Format(
                  "TEST-6...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-30, 22, 52, 78}, 2, 3, 
                  false
              );
              Console.WriteLine(string.Format(
                  "TEST-7...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 21, 16, 
                  false
              );
              Console.WriteLine(string.Format(
                  "TEST-8...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{1, 4, 6, 9, 10, 11, 11, 16, 16, 20, 23, 26, 28, 28, 40, 41, 41, 44, 48, 49, 50, 51, 52, 58, 58, 72, 77, 83, 83, 92, 92, 98}, 29, 27, 
                  true
              );
              Console.WriteLine(string.Format(
                  "TEST-9...{0}",
                  result)
              );
          }
      }
  }
  
source_py: def find_a_triplet_that_sum_to_a_given_value_1(A, arr_size, sum):
      A.sort()
      for i in range(0, (arr_size - 2)):
          l = (i + 1)
          r = (arr_size - 1)
          while (l < r):
              if (((A[i] + A[l]) + A[r]) == sum):
                  print('Triplet is', A[i], ', ', A[l], ', ', A[r])
                  return True
              elif (((A[i] + A[l]) + A[r]) < sum):
                  l += 1
              else:
                  r -= 1
      return False
source_cpp: bool find_a_triplet_that_sum_to_a_given_value_1(vector<int> A, int arr_size, int sum) {
    int l, r;
    sort(A.begin(), A.end());
    for ( int i = 0;
    i < arr_size - 2;
    i ++ ) {
      l = i + 1;
      r = arr_size - 1;
      while ( l < r ) {
        if ( A [ i ] + A [ l ] + A [ r ] == sum ) {
          return true;
        }
        else if ( A [ i ] + A [ l ] + A [ r ] < sum ) l ++;
        else r --;
      }
    }
    return false;
  }