title: Dice Throw Problem 1
signature: function dice_throw_problem_1(f, d, s)
source_py: def dice_throw_problem_1(f, d, s):
      mem = [[0 for i in range((s + 1))] for j in range((d + 1))]
      mem[0][0] = 1
      for i in range(1, (d + 1)):
          for j in range(1, (s + 1)):
              mem[i][j] = (mem[i][(j - 1)] + mem[(i - 1)][(j - 1)])
              if (((j - f) - 1) >= 0):
                  mem[i][j] -= mem[(i - 1)][((j - f) - 1)]
      return mem[d][s]
source_cpp: long dice_throw_problem_1(int f, int d, int s) {
    long mem [ d + 1 ] [ s + 1 ];
    memset ( mem, 0, sizeof mem );
    mem [ 0 ] [ 0 ] = 1;
    for ( int i = 1;
    i <= d;
    i ++ ) {
      for ( int j = i;
      j <= s;
      j ++ ) {
        mem [ i ] [ j ] = mem [ i ] [ j - 1 ] + mem [ i - 1 ] [ j - 1 ];
        if ( j - f - 1 >= 0 ) mem [ i ] [ j ] -= mem [ i - 1 ] [ j - f - 1 ];
      }
    }
    return mem [ d ] [ s ];
  }
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(f, d, s, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(f, d, s) 
      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(57, 5, 33, 35960)
      print(string.format("TEST-0...%s",result))
  
      result = driver(58, 45, 4, 0)
      print(string.format("TEST-1...%s",result))
  
      result = driver(38, 89, 9, 0)
      print(string.format("TEST-2...%s",result))
  
      result = driver(5, 39, 30, 0)
      print(string.format("TEST-3...%s",result))
  
      result = driver(91, 90, 47, 0)
      print(string.format("TEST-4...%s",result))
  
      result = driver(76, 56, 46, 0)
      print(string.format("TEST-5...%s",result))
  
      result = driver(97, 26, 52, 247959266474052)
      print(string.format("TEST-6...%s",result))
  
      result = driver(97, 90, 90, 1)
      print(string.format("TEST-7...%s",result))
  
      result = driver(99, 2, 26, 25)
      print(string.format("TEST-8...%s",result))
  
  end
  
  main()
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": 35960, "inputs": {"f": 57, "d": 5, "s": 33}}, {"idx": 1, "outputs": 0, "inputs": {"f": 58, "d": 45, "s": 4}}, {"idx": 2, "outputs": 0, "inputs": {"f": 38, "d": 89, "s": 9}}, {"idx": 3, "outputs": 0, "inputs": {"f": 5, "d": 39, "s": 30}}, {"idx": 4, "outputs": 0, "inputs": {"f": 91, "d": 90, "s": 47}}, {"idx": 5, "outputs": 0, "inputs": {"f": 76, "d": 56, "s": 46}}, {"idx": 6, "outputs": 247959266474052, "inputs": {"f": 97, "d": 26, "s": 52}}, {"idx": 7, "outputs": 1, "inputs": {"f": 97, "d": 90, "s": 90}}, {"idx": 8, "outputs": 25, "inputs": {"f": 99, "d": 2, "s": 26}}]
question_info.extension: lua
question_info.entry_fn_name: dice_throw_problem_1
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8
question_info.commands: lua __FILENAME__