title: Compute Ncr P Set 1 Introduction And Dynamic Programming Solution
signature: function compute_ncr_p_set_1_introduction_and_dynamic_programming_solution(n, r, p)
source_py: def compute_ncr_p_set_1_introduction_and_dynamic_programming_solution(n, r, p):
      C = [0 for i in range((r + 1))]
      C[0] = 1
      for i in range(1, (n + 1)):
          for j in range(min(i, r), 0, (- 1)):
              C[j] = ((C[j] + C[(j - 1)]) % p)
      return C[r]
source_cpp: int compute_ncr_p_set_1_introduction_and_dynamic_programming_solution(int n, int r, int p) {
    int C [ r + 1 ];
    memset ( C, 0, sizeof ( C ) );
    C [ 0 ] = 1;
    for ( int i = 1;
    i <= n;
    i ++ ) {
      for ( int j = min ( i, r );
      j > 0;
      j -- ) C [ j ] = ( C [ j ] + C [ j - 1 ] ) % p;
    }
    return C [ r ];
  }
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(n, r, p, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(n, r, p) 
      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(82, 5, 94, 50)
      print(string.format("TEST-0...%s",result))
  
      result = driver(45, 24, 95, 80)
      print(string.format("TEST-1...%s",result))
  
      result = driver(44, 68, 61, 0)
      print(string.format("TEST-2...%s",result))
  
      result = driver(88, 24, 43, 0)
      print(string.format("TEST-3...%s",result))
  
      result = driver(90, 75, 57, 0)
      print(string.format("TEST-4...%s",result))
  
      result = driver(98, 55, 43, 2)
      print(string.format("TEST-5...%s",result))
  
      result = driver(80, 54, 88, 0)
      print(string.format("TEST-6...%s",result))
  
      result = driver(60, 75, 65, 0)
      print(string.format("TEST-7...%s",result))
  
      result = driver(52, 73, 86, 0)
      print(string.format("TEST-8...%s",result))
  
      result = driver(71, 26, 45, 12)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": 50, "inputs": {"n": 82, "r": 5, "p": 94}}, {"idx": 1, "outputs": 80, "inputs": {"n": 45, "r": 24, "p": 95}}, {"idx": 2, "outputs": 0, "inputs": {"n": 44, "r": 68, "p": 61}}, {"idx": 3, "outputs": 0, "inputs": {"n": 88, "r": 24, "p": 43}}, {"idx": 4, "outputs": 0, "inputs": {"n": 90, "r": 75, "p": 57}}, {"idx": 5, "outputs": 2, "inputs": {"n": 98, "r": 55, "p": 43}}, {"idx": 6, "outputs": 0, "inputs": {"n": 80, "r": 54, "p": 88}}, {"idx": 7, "outputs": 0, "inputs": {"n": 60, "r": 75, "p": 65}}, {"idx": 8, "outputs": 0, "inputs": {"n": 52, "r": 73, "p": 86}}, {"idx": 9, "outputs": 12, "inputs": {"n": 71, "r": 26, "p": 45}}]
question_info.extension: lua
question_info.entry_fn_name: compute_ncr_p_set_1_introduction_and_dynamic_programming_solution
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: lua __FILENAME__