title: Bell Numbers Number Of Ways To Partition A Set
signature: function bell_numbers_number_of_ways_to_partition_a_set(n)
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, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(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(9, 21147)
      print(string.format("TEST-0...%s",result))
  
      result = driver(4, 15)
      print(string.format("TEST-1...%s",result))
  
      result = driver(6, 203)
      print(string.format("TEST-2...%s",result))
  
  end
  
  main()
source_py: def bell_numbers_number_of_ways_to_partition_a_set(n):
      bell = [[0 for i in range((n + 1))] for j in range((n + 1))]
      bell[0][0] = 1
      for i in range(1, (n + 1)):
          bell[i][0] = bell[(i - 1)][(i - 1)]
          for j in range(1, (i + 1)):
              bell[i][j] = (bell[(i - 1)][(j - 1)] + bell[i][(j - 1)])
      return bell[n][0]
source_cpp: int bell_numbers_number_of_ways_to_partition_a_set(int n) {
    int bell [ n + 1 ] [ n + 1 ];
    bell [ 0 ] [ 0 ] = 1;
    for ( int i = 1;
    i <= n;
    i ++ ) {
      bell [ i ] [ 0 ] = bell [ i - 1 ] [ i - 1 ];
      for ( int j = 1;
      j <= i;
      j ++ ) bell [ i ] [ j ] = bell [ i - 1 ] [ j - 1 ] + bell [ i ] [ j - 1 ];
    }
    return bell [ n ] [ 0 ];
  }