title: Sum Two Large Numbers
signature: function sum_two_large_numbers(str1, str2)
test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(str1, str2, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(str1, str2) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver("VkfzrPG", "rKZ", "44527855")
      print(string.format("TEST-0...%s",result))
  
      result = driver("0526110506447", "903", "0526110507350")
      print(string.format("TEST-1...%s",result))
  
      result = driver("011010010", "110100000", "121110010")
      print(string.format("TEST-2...%s",result))
  
      result = driver("sPAwZACc ", "liYMsojPiinOV", "66153436372942")
      print(string.format("TEST-3...%s",result))
  
      result = driver("3", "611", "614")
      print(string.format("TEST-4...%s",result))
  
      result = driver("0101", "01110101011", "01110101112")
      print(string.format("TEST-5...%s",result))
  
      result = driver("VTtNu", "Wsmc", "469530")
      print(string.format("TEST-6...%s",result))
  
      result = driver("2317170", "898421173423", "898423490593")
      print(string.format("TEST-7...%s",result))
  
      result = driver("111111000010", "01100001110111", "01211112110121")
      print(string.format("TEST-8...%s",result))
  
      result = driver("Ktt", "CTbbVX wGBkE", "2315420138859")
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
source_py: def sum_two_large_numbers(str1, str2):
      if (len(str1) > len(str2)):
          t = str1
          str1 = str2
          str2 = t
      str = ''
      n1 = len(str1)
      n2 = len(str2)
      str1 = str1[::(- 1)]
      str2 = str2[::(- 1)]
      carry = 0
      for i in range(n1):
          sum = ((ord(str1[i]) - 48) + ((ord(str2[i]) - 48) + carry))
          str += chr(((sum % 10) + 48))
          carry = int((sum / 10))
      for i in range(n1, n2):
          sum = ((ord(str2[i]) - 48) + carry)
          str += chr(((sum % 10) + 48))
          carry = int((sum / 10))
      if carry:
          str += chr((carry + 48))
      str = str[::(- 1)]
      return str
source_cpp: string sum_two_large_numbers(string str1, string str2) {
    if ( str1 . length ( ) > str2 . length ( ) ) swap ( str1, str2 );
    string str = "";
    int n1 = str1 . length ( ), n2 = str2 . length ( );
    reverse ( str1 . begin ( ), str1 . end ( ) );
    reverse ( str2 . begin ( ), str2 . end ( ) );
    int carry = 0;
    for ( int i = 0;
    i < n1;
    i ++ ) {
      int sum = ( ( str1 [ i ] - '0' ) + ( str2 [ i ] - '0' ) + carry );
      str . push_back ( sum % 10 + '0' );
      carry = sum / 10;
    }
    for ( int i = n1;
    i < n2;
    i ++ ) {
      int sum = ( ( str2 [ i ] - '0' ) + carry );
      str . push_back ( sum % 10 + '0' );
      carry = sum / 10;
    }
    if ( carry ) str . push_back ( carry + '0' );
    reverse ( str . begin ( ), str . end ( ) );
    return str;
  }