title: Find The Missing Number 2
signature: function find_the_missing_number_2(a, n)
source_py: def find_the_missing_number_2(a, n):
      x1 = a[0]
      x2 = 1
      for i in range(1, n):
          x1 = (x1 ^ a[i])
      for i in range(2, (n + 2)):
          x2 = (x2 ^ i)
      return (x1 ^ x2)
source_cpp: int find_the_missing_number_2(vector<int> a, int n) {
    int x1 = a [ 0 ];
    int x2 = 1;
    for ( int i = 1;
    i < n;
    i ++ ) x1 = x1 ^ a [ i ];
    for ( int i = 2;
    i <= n + 1;
    i ++ ) x2 = x2 ^ i;
    return ( x1 ^ x2 );
  }
question_info.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(a, n, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(a, n) 
      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({2, 5, 7, 8, 10, 14, 27, 32, 51, 52, 57, 58, 65, 68, 68, 72, 73, 73, 83, 92, 98}, 12, 50)
      print(string.format("TEST-0...%s",result))
  
      result = driver({-60, -48, 38, -78, 88, 86, -4, -94, 16, -64, 32, 88, 58, -78, -16, 48, 38, 30, 66, -60, 20, 40, -28, -64, -48, -86, -80, -8, -58, 52, 80, -32, 46, -4, -70, 76, -4, 78, -64, 38, -40}, 28, -91)
      print(string.format("TEST-1...%s",result))
  
      result = driver({0, 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, 1, 1, 1, 1, 1}, 38, 1)
      print(string.format("TEST-2...%s",result))
  
      result = driver({69, 59, 22, 33, 69, 28, 11, 34, 72, 88, 16, 30, 69, 89, 43, 4, 65, 85, 27}, 13, 109)
      print(string.format("TEST-3...%s",result))
  
      result = driver({-98, -98, -92, -88, -88, -82, -74, -70, -68, -60, -60, -48, -38, -34, -34, -24, 14, 38, 50, 58, 62, 64, 64, 68, 76, 78, 78, 86, 88, 90, 92, 98, 98}, 23, 94)
      print(string.format("TEST-4...%s",result))
  
      result = driver({0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0}, 41, 42)
      print(string.format("TEST-5...%s",result))
  
      result = driver({1, 9, 12, 12, 24, 25, 33, 33, 36, 39, 46, 48, 48, 52, 52, 53, 57, 69, 71, 72, 75, 76, 78, 80, 82, 86, 89, 91, 94, 95, 96, 97, 98, 99}, 30, 124)
      print(string.format("TEST-6...%s",result))
  
      result = driver({62, -66, 60, -92, 46, 6, -52, 48, 72, -64, 34, 20, 50, 70, -34, 20, -70, 14, -44, 66, -70}, 17, 101)
      print(string.format("TEST-7...%s",result))
  
      result = driver({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, 1}, 30, 0)
      print(string.format("TEST-8...%s",result))
  
      result = driver({33, 10, 6, 71, 18, 22, 15, 57, 56, 63, 35, 93, 31, 43, 98, 99, 62, 39, 44, 86, 78, 95, 6, 76, 71}, 12, 32)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": 50, "inputs": {"a": [2, 5, 7, 8, 10, 14, 27, 32, 51, 52, 57, 58, 65, 68, 68, 72, 73, 73, 83, 92, 98], "n": 12}}, {"idx": 1, "outputs": -91, "inputs": {"a": [-60, -48, 38, -78, 88, 86, -4, -94, 16, -64, 32, 88, 58, -78, -16, 48, 38, 30, 66, -60, 20, 40, -28, -64, -48, -86, -80, -8, -58, 52, 80, -32, 46, -4, -70, 76, -4, 78, -64, 38, -40], "n": 28}}, {"idx": 2, "outputs": 1, "inputs": {"a": [0, 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, 1, 1, 1, 1, 1], "n": 38}}, {"idx": 3, "outputs": 109, "inputs": {"a": [69, 59, 22, 33, 69, 28, 11, 34, 72, 88, 16, 30, 69, 89, 43, 4, 65, 85, 27], "n": 13}}, {"idx": 4, "outputs": 94, "inputs": {"a": [-98, -98, -92, -88, -88, -82, -74, -70, -68, -60, -60, -48, -38, -34, -34, -24, 14, 38, 50, 58, 62, 64, 64, 68, 76, 78, 78, 86, 88, 90, 92, 98, 98], "n": 23}}, {"idx": 5, "outputs": 42, "inputs": {"a": [0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0], "n": 41}}, {"idx": 6, "outputs": 124, "inputs": {"a": [1, 9, 12, 12, 24, 25, 33, 33, 36, 39, 46, 48, 48, 52, 52, 53, 57, 69, 71, 72, 75, 76, 78, 80, 82, 86, 89, 91, 94, 95, 96, 97, 98, 99], "n": 30}}, {"idx": 7, "outputs": 101, "inputs": {"a": [62, -66, 60, -92, 46, 6, -52, 48, 72, -64, 34, 20, 50, 70, -34, 20, -70, 14, -44, 66, -70], "n": 17}}, {"idx": 8, "outputs": 0, "inputs": {"a": [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, 1], "n": 30}}, {"idx": 9, "outputs": 32, "inputs": {"a": [33, 10, 6, 71, 18, 22, 15, 57, 56, 63, 35, 93, 31, 43, 98, 99, 62, 39, 44, 86, 78, 95, 6, 76, 71], "n": 12}}]
question_info.extension: lua
question_info.entry_fn_name: find_the_missing_number_2
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: lua __FILENAME__